JQuery does all that and calls success callback if call succeed or error callback if it fails. Jquery also support promise out of box. $. ajax returns a promise object, so that we don't have to pass a callback function.
The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.
A Promise is an interface for asynchronous operations. An ajax request is a very specific asynchronous operation.
I have my Promise defined as so:
myFunc = function() {
$.getJSON("./rest/api/some/url", function(json, textStatus) {
console.log("AJAX call hit!");
});
};
$.when(myFunc()).then(function() {
console.log("Then block hit!");
});
and in console it's being output as:
Then block hit!
AJAX call hit!
I need the AJAX call hit!
first followed by the Then block hit!
.
Any idea why this is happening? I even tried to implement a custom callback function (a standard example I found on Stackoverflow) and it still doesn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With