Ok, so I need to open a dialog (jQuery UI) before performing the actual AJAX request and depending on what the user chooses, continue with the AJAX request or simply do nothing.
Unfortunately the function seems to be returning early and ignores the synchronous request completely. What am I doing wrong?
Here’s the code:
function saveSomeStuff(value) {
var returnvalue = this.revert;
$("#dialog").dialog({
draggable: false,
buttons: {
"OK": function() {
$(this).dialog("close");
returnvalue = $.ajax({
type: "POST",
url: config.someUrl,
async: false,
data : {/* some data */}
}).responseText;
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
return returnvalue;
}
P.S. Avoid synchronous requests everywhere.