deferred.state()
JQ Home <<
Objects <<
deferred.state()
Deferred state.
Description
The deferred.state()
Deferred method, returns a string representing the current state of a Deferred object.
- The Deferred object can be in one of three states:
- pending - The initial state of a
Deferred
object which it remains in until it is resolved or rejected. - resolved - The
Deferred
object has been called using thedeferred.resolve()
or thedeferred.resolveWith()
methods thus moving theDeferred
object to a resolved state. - rejected - The
Deferred
object has been called using thedeferred.reject()
or thedeferred.rejectWith()
methods thus moving theDeferred
object to a rejected state.
- pending - The initial state of a
Syntax
Signature | Description |
---|---|
deferred.state() | Determine the current state of a Deferred object. |
Parameters
None.
Return
A String
object.
deferred.state()
ExamplesObjects << Top
Determine the current state of a Deferred object.
In the example below when we press the button the first time we create a Deferred
object . We then notify and resolve
the Deferred
object and process any progressCallbacks and doneCallbacks.
$(function(){
$('#btn16').one('click', function(){
var ourDeferred = $.Deferred();
ourDeferred.always( eFunc );
$('#div1').append( 'Current state of ourDeferred: ' + ourDeferred.state() + ' <br>');
ourDeferred.resolve( 'Our deferred was resolved. <br>', '#div1');
$('#div1').append( 'Current state of ourDeferred: ' + ourDeferred.state() + ' <br>');
});
function eFunc( value, div ){
$(div).append( 'In eFunc: ' + value);
}
});
div1. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 7 - The Deferred Object