What arguments are supplied to the function inside an ajax .done?

后端 未结 3 1649
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 08:12

I have the following:

    $.ajax(link.href,
    {
        cache: false,
        dataType: \'html\'
    })
        .done(onDialogDone)
        .fail(onDialogFail)         


        
相关标签:
3条回答
  • 2021-02-02 09:03

    The arguments for .done() and .fail() are the same as the arguments for the corresponding success: and error: parameters for the $.ajax() function, namely:

    .done( function(data, textStatus, jqXHR) { ... } );
    

    and

    .fail( function(jqXHR, textStatus, errorThrown) { ... } );
    

    For the purposes of typescript, textStatus and errorThrown are strings, jqXHR is an Object, and data depends on what the remote server sends you.

    0 讨论(0)
  • 2021-02-02 09:03

    Check this out:

    Methods (part of jqXHR and Deferred implementations, shown here for clarity only)

     .ajax().always(function(a, textStatus, b){});
    

    Replaces method .complete() which was deprecated in jQuery 1.8. In response to successful transaction, arguments are same as .done() (ie. a = data, b = jqXHR) and for failed transactions the arguments are same as .fail() (ie. a = jqXHR, b = errorThrown). This is an alternative construct for the complete callback function above. Refer to deferred.always() for implementation details.

        .ajax().done(function(data, textStatus, jqXHR){});
    

    Replaces method .success() which was deprecated in jQuery 1.8. This is an alternative construct for the success callback function above. Refer to deferred.done() for implementation details.

        .ajax().fail(function(jqXHR, textStatus, errorThrown){});
    

    Replaces method .error() which was deprecated in jQuery 1.8. This is an alternative construct for the complete callback function above. Refer to deferred.fail() for implementation details.

        .ajax().then(function(data, textStatus, jqXHR){}, function(jqXHR, textStatus, errorThrown){});
    

    Incorporates the functionality of .done() and .fail() methods. Refer to deferred.then() for implementation details.

        .ajax().pipe(function(data, textStatus, jqXHR){}, function(jqXHR, textStatus, errorThrown){});
    

    Incorporates the functionality of .done() and .fail() methods, allowing the underlying Promise to be manipulated. Refer to deferred.pipe() for implementation details.

    0 讨论(0)
  • 2021-02-02 09:08

    The three parameters passed to the done handler are:

    data, textStatus, jqXHR
    

    You can read more here: http://api.jquery.com/jQuery.ajax/

    1. data is the response message
    2. textStatus will always be success in the done function
    3. jqXHR is the raw XMLHttpRequest
    0 讨论(0)
提交回复
热议问题