How can i check and wait for the server lag for the save function to complete, which returns an ajax object jqxhr, I want to check if the ajax request is complete or not before i do anything else else.
Note : the save function has success, complete errors etc.. I want to make sure its complete before i do anything so that i dotn get undefined when i use jqxhr.status.
$(document).ready(function() {
$(function() {
$("#save").click(function() {
save().then(function(jqxhr){// check status...
alert(" jqxhr status " + jqxhr.status); <--getting undefined first
//200 for success
var stat = jqxhr.status;
//alert(" inside 200 status "+stat);
if (stat == 200) {
console.log("inside 200");
alert(" inside 200 status " + stat);
}
if (stat == 400) {
console.log("inside 400");
alert(" inside 400 status " + stat);
} else {
alert(" inside 200 status " + stat);
}
});
});
});
});
The save() function (which is actually just an ajax call) returns a promise, so you can use then() to chain your code: