jQuery ajax() success, error VS .done(), .fail()

jQuery ajax() success, error VS .done(), .fail()   

success and Error : A success callback that gets invoked upon successful completion of an Ajax request.

A failure callback that gets invoked in case there is any error while making the request.

Example:

 $.ajax({
        url: ‘URL‘,
        type: ‘POST‘,
        data: yourData,
        datatype: ‘json‘,
        success: function (data) { successFunction(data); },
        error: function (jqXHR, textStatus, errorThrown) { errorFunction(); }
    });

       

.done() and .fail() :

.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.

.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.

$.ajax({
    url: ‘URL‘,
    type: ‘POST‘,
    data: yourData,
    datatype: ‘json‘
})
.done(function (data) { successFunction(data); })
.fail(function (jqXHR, textStatus, errorThrown) { serrorFunction(); });

             

jQuery ajax() success, error VS .done(), .fail()

上一篇:说明 http express 和 koa 的路由参数分别怎么获取2-简单说明动态路由、说明 express 和 koa 的中间件的使用、简述 koa 的洋葱圈模型、扩展:了解 websocket


下一篇:Node.js回调函数和事件循环机制