Readonly
readyReturns client's state.
Optional
responseJSONReadonly
responseReturns response as text.
Throws an "InvalidStateError" DOMException if responseType is not the empty string or "text".
Optional
Readonly
responseXMLReturns the response as document.
Throws an "InvalidStateError" DOMException if responseType is not the empty string or "document".
Readonly
statusReadonly
statusAdd handlers to be called when the Deferred object is either resolved or rejected.
A function, or array of functions, that is called when the Deferred is resolved or rejected.
Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected.
$.get( "test.php" ).always(function() {
alert( "$.get completed with success or error callback arguments" );
});
Add handlers to be called when the Deferred object is resolved.
A function, or array of functions, that are called when the Deferred is resolved.
Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>deferred.done demo</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>
<body>
<button>Go</button>
<p>Ready...</p>
<script>
// 3 functions to call when the Deferred object is resolved
function fn1() {
$( "p" ).append( " 1 " );
}
function fn2() {
$( "p" ).append( " 2 " );
}
function fn3( n ) {
$( "p" ).append( n + " 3 " + n );
}
// Create a deferred object
var dfd = $.Deferred();
// Add handlers to be called when dfd is resolved
dfd
// .done() can take any number of functions or arrays of functions
.done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
// We can chain done methods, too
.done(function( n ) {
$( "p" ).append( n + " we're done." );
});
// Resolve the Deferred object when the button is clicked
$( "button" ).on( "click", function() {
dfd.resolve( "and" );
});
</script>
</body>
</html>
Add handlers to be called when the Deferred object is rejected.
A function, or array of functions, that are called when the Deferred is rejected.
Optional additional functions, or arrays of functions, that are called when the Deferred is rejected.
$.get( "test.php" )
.done(function() {
alert( "$.get succeeded" );
})
.fail(function() {
alert( "$.get failed!" );
});
Acts as if the Content-Type
header value for a response is mime. (It does not change the header.)
Throws an "InvalidStateError" DOMException if state is loading or done.
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var defer = $.Deferred(),
filtered = defer.pipe( null, function( value ) {
return value * 3;
});
defer.reject( 6 );
filtered.fail(function( value ) {
alert( "Value is ( 3*6 = ) 18: " + value );
});
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: (An optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var defer = $.Deferred(),
filtered = defer.pipe( null, function( value ) {
return value * 3;
});
defer.reject( 6 );
filtered.fail(function( value ) {
alert( "Value is ( 3*6 = ) 18: " + value );
});
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Utility method to filter and/or chain Deferreds.
An optional function that is called when the Deferred is resolved.
Optional
failFilter: nullAn optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
Deprecated since 1.8. Use <a href="index.SDK.JQueryXHR.html#then" class="tsd-kind-method">then</a>
.
Cause: The .pipe()
method on a jQuery.Deferred
object was deprecated as of jQuery 1.8, when the .then()
method was changed to perform the same function.
Solution: In most cases it is sufficient to change all occurrences of .pipe()
to .then()
. Ensure that you aren't relying on context/state propagation (e.g., using this
) or synchronous callback invocation, which were dropped from .then()
for Promises/A+ interoperability as of jQuery 3.0.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.pipe(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object generates progress notifications.
A function, or array of functions, to be called when the Deferred generates progress notifications.
Optional additional functions, or arrays of functions, to be called when the Deferred generates progress notifications.
Return a Deferred's Promise object.
Object onto which the promise methods have to be attached
function asyncEvent() {
var dfd = jQuery.Deferred();
// Resolve after a random interval
setTimeout(function() {
dfd.resolve( "hurray" );
}, Math.floor( 400 + Math.random() * 2000 ) );
// Reject after a random interval
setTimeout(function() {
dfd.reject( "sorry" );
}, Math.floor( 400 + Math.random() * 2000 ) );
// Show a "working..." message every half-second
setTimeout(function working() {
if ( dfd.state() === "pending" ) {
dfd.notify( "working... " );
setTimeout( working, 500 );
}
}, 1 );
// Return the Promise so caller can't change the Deferred
return dfd.promise();
}
// Attach a done, fail, and progress handler for the asyncEvent
$.when( asyncEvent() ).then(
function( status ) {
alert( status + ", things are going well" );
},
function( status ) {
alert( status + ", you fail this time" );
},
function( status ) {
$( "body" ).append( status );
}
);
Return a Deferred's Promise object.
// Existing object
var obj = {
hello: function( name ) {
alert( "Hello " + name );
}
},
// Create a Deferred
defer = $.Deferred();
// Set object as a promise
defer.promise( obj );
// Resolve the deferred
defer.resolve( "John" );
// Use the object as a Promise
obj.done(function( name ) {
obj.hello( name ); // Will alert "Hello John"
}).hello( "Karl" ); // Will alert "Hello Karl"
Combines a header in author request headers.
Throws an "InvalidStateError" DOMException if either state is not opened or the send() flag is set.
Throws a "SyntaxError" DOMException if name is not a header name or if value is not a header value.
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>deferred.then demo</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>
<body>
<button>Filter Resolve</button>
<p></p>
<script>
var filterResolve = function() {
var defer = $.Deferred(),
filtered = defer.then(function( value ) {
return value * 2;
});
defer.resolve( 5 );
filtered.done(function( value ) {
$( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
});
};
$( "button" ).on( "click", filterResolve );
</script>
</body>
</html>
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
An optional function that is called when progress notifications are sent to the Deferred.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: (An optional function that is called when progress notifications are sent to the Deferred.
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>deferred.then demo</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>
<body>
<button>Filter Resolve</button>
<p></p>
<script>
var filterResolve = function() {
var defer = $.Deferred(),
filtered = defer.then(function( value ) {
return value * 2;
});
defer.resolve( 5 );
filtered.done(function( value ) {
$( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
});
};
$( "button" ).on( "click", filterResolve );
</script>
</body>
</html>
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
An optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
An optional function that is called when the Deferred is resolved.
Optional
failFilter: nullAn optional function that is called when the Deferred is rejected.
Optional
progressFilter: nullAn optional function that is called when progress notifications are sent to the Deferred.
var request = $.ajax( url, { dataType: "json" } ),
chained = request.then(function( data ) {
return $.ajax( url2, { data: { user: data.userId } } );
});
chained.done(function( data ) {
// data retrieved from url2 as provided by the first request
});
See
<a href="https://api.jquery.com/jquery.ajax/#jqXHR">https://api.jquery.com/jquery.ajax/#jqXHR</a>