I am working in a web application using Spring MVC . I am trying to show a confirmation dialog before submitting the form using Bootbox , but I am getting an internal 500 server error.
This is my form:
<form id="checkout-form" class="smart-form" novalidate="novalidate"> ...some fields <button type="button" class="btn btn-primary" onclick="insertFunction()"> Accept </button> </form>
This is my insertFunction ()
function insertFunction(){ var name = $('#name').val(); var lastname = $('#lastname').val(); var confirmSend; var json = {"name": name,"lastname": lastname}; $.ajax({ type: "POST", url: "register/insertPerson", data: JSON.stringify(json), contentType: "application/json; charset=utf-8", dataType: "json", cache: false, beforeSend: function (xhr){ bootbox.dialog({ message: "I am a custom dialog", title: "Custom title", buttons: { success: { label: "Success!", className: "btn-success", callback: function() { //I DONT KNOW WHAT TO DO HERE } }, danger: { label: "Danger!", className: "btn-danger", callback: function() { return false; } } } }); xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("Content-Type", "application/json"); }, success: function (data){ if (data.message === true){ bootbox.alert("OPERATION WAS EXECUTED WITHOUT PROBLEMS"); } else { bootbox.alert("OPERATION FAILED"); } }, error: function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }); }
I send the first and last name to my spring controller, and I insert, and if it was successful, my method method returns true, and in the success block of my script, I check if is true I show the message, and if it is false, I show another message.
My problem is that I do not know what to do in this section:
success: { label: "Success!", className: "btn-success", callback: function() { //I DONT KNOW WHAT TO DO HERE } }
* EDIT: * It was my mistake representing the value in the form fields, now I donโt get the internal 500 server internal error, now it shows me my FAILED dialog, which I run in the success block
else { bootbox.alert("OPERATION FAILED");
and then after this message is shown below, it will display the confirmation dialog that I want to show. It looks like this is showing me messages in the wrong order. Also, when I click the โDangerโ button, it does not close the dialog box only if I click โSuccessโ.
* EDIT 2: *
Confirmation windows work, but I have problems when I press the cancel button, when I press the cancel button, the window does not close.
function preInsert() { bootbox.dialog({ message: "are you sure", title: "are you sure", buttons: { success: { label: "Acept", className: "btn-success", callback: function () { realInsert(); } }, danger: { label: "Cancel", className: "btn-danger", callback: function () { return false; } } } }); } function realInsert() { var name= $('#name').val(); var lastName= $('#lastName').val(); var json = {"name": name, "lastName": lastName }; $.ajax( { type: "POST", url: "register/insertForm", data: JSON.stringify(json), contentType: "application/json; charset=utf-8", dataType: "json", cache: false, beforeSend: function (xhr) { xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("Content-Type", "application/json"); }, success: function (data) { if (data === true) { bootbox.alert("Insert Successfully "); } else { bootbox.alert("Problem during the insert"); } }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }); }