Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery deferred.fail() method

jQuery deferred.fail() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

Example

deferred.fail() is called when the Deferred object is rejected

$

(

function

(

)

{

$.

get

(

"

test.php

"

)

.

done

(

function

(

)

{

alert

(

"

$.get succeeded!

"

)

;

}

)

.

fail

(

function

(

)

{

alert

(

"

$.get failed!

"

)

;

}

)

;

}

)

Try it »


Definition and Usage

The deferred.fail() function calls the added handlers when the Deferred object is rejected.
**Tip:** This method accepts one or more arguments. deferred.fail() returns a Deferred object, so other deferred object methods can be chained to it, including additional .fail() methods. When the Deferred object is rejected, the callbacks are executed in the order in which they were added, and can be passed as arguments to methods such as: deferred.resolve() or deferred.rejectWith().


Syntax

deferred.fail( failCallbacks [, failCallbacks ] )

Parameters Description
failCallbacks Function type: A function or an array of functions called when the Deferred object is rejected
failCallbacks Optional. Function type: A function or an array of functions called when the Deferred object is rejected

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods