-3

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type = "text/javascript">
function getProducts(){
    $.ajax(
        {
            type: "GET",
            url: "/SOSv8/api/products",
            dataType: "json",
            success: function(data)
            {
                $('#products').dataTable({
                    "data" : data,
                    "columns" : [{"data" : "name"}, {"data" : "descript"}, {"data" : "code"}, {"defaultContent" : "<button>delete</button>"}]
                });
            $('#products').on('click', 'button', function (){
                    $("#dialog").dialog(
                        {
                            width: '500px',
                            buttons: {
                                ok: function(){$("#delete").submit()},
                                cancel: function(){$(this).dialog('close')}
                            }

                    });
            });
            },
            Error: function (xhr, ajaxOptions, thrownError)
            {
                alert(xhr.status);
                alert(thrownError);

            }
        }   

    )
}
function dialog() {
    $( "#dialog" ).dialog(
        {
            width: '500px',
            buttons: {
                ok: function(){$("#delete").submit()},
                cancel: function(){$(this).dialog('close')}
            }
        }
    );
} 
$(document).ready(getProducts);
 </script>
        <table id="products" style="width:50%" border="1">
            <thead>
                <tr style="background-color:#A0A0A0">
                    <th><label>Name</label></th>
                    <th><label>Description</label></th>
                    <th><label>Code</label></th>
                    <th><label>Options</label></th>
                </tr>
            </thead>
        </table>

<div id="dialog" title="" >
    <P> are you sure you want delete this code?</P> 
</div>

<form:form id="delete" method="POST"  modelAttribute="product" action="deleteProduct">
<form:hidden path="id" value="${product.id}" />
</form:form>
|

1

0

$('formId').submit(function(){
    // do some debugging here and return true to perform the submit or false to cancel
    console.log(idToDelete);
    return true;
});
|