jquery ajax always code example
Example 1: jquery wait for all ajax requests to complete
$.when(ajaxCall1(), ajaxCall2()).done(function(ajax1Results,ajax2Results){
});
function ajaxCall1() {
return $.ajax({
url: "some_url.php",
success: function(result){
console.log(result);
}
});
}
function ajaxCall2() {
return $.ajax({
url: "some_url.php",
success: function(result){
console.log(result);
}
});
}
Example 2: jquery ajax on fail
fail: function(xhr, textStatus, errorThrown){
alert('request failed');
}