I’ve got some code that calls via jQuery and Ajax an asp page to do an insert of a record. I think it’s throwing errors, but I don’t know how to “wait” out a response and only then redirect the client. Right now it fires the ajax and redirects. I don’t know how to make a callback using ASP/Ajax to wait for the return.
/* AJAX TUTORIAL SUBMIT ---------------------------------------- */
function post_Tutorial_Submit(serial,critiqueText) {
var jsonToSend={ serial: serial, critiqueText: critiqueText} ;
$.ajax({
type: "POST",
url: 'AJAX_Tutor_Tutorial_Submit.asp',
data: jsonToSend,
success: function(response) {
// $("#spnSaveResponse").text(response);
},
error:function (xhr, ajaxOptions, thrownError){
// alert(xhr.responseText);
// alert(thrownError);
}
}); // end ajax
} // end post_tutorial_submit
$( "#dialog-message-submit" ).dialog({
modal: true,
buttons: {
"OK": function() {
var critiqueText=$("#critique").val();
var serial=$("#draft_serial").val();
var response=post_Tutorial_Submit(serial,critiqueText);
$( this ).dialog( "close" );
window.location.href="../admin/admin_control.asp?message=submitted&serial="+serial;
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
}); //dialog
You need to put your code in jQuery’s
success: function(response) { ... }callback.