HTML and CSS Reference
In-Depth Information
A promise has a lifecycle. At any point in time it may be in one of three states: “un-
fulfilled”, “fulfilled” or “failed”. The promise may only move from “unfulfilled” to “ful-
filled”, or “unfulfilled” to “failed”. Once a promise has been “fulfilled” or “failed”, its
value cannot not be changed.
The following code shows the same example written to work with promises.
promise = $.ajax({
type : "GET",
url : "/server/tasks.json",
cache : false
promise.done(function(data) {
}); {
console.log('A failure occurred');
When the promise is initially created it has a state of “unfulfilled”. Once the response is
successfully received, the promise is set to “fulfilled”, and the relevant callback (“done”)
Search WWH ::

Custom Search