开发者

What do the arguments inside an ajax function refer to?

I often see this in ajax function function(event, data, status, xhr). I'm 开发者_运维百科wondering what those arguments refer to and how they are used.


  • data: The data returned by the server (could be HTML, XML, JSON, ...)
  • status: a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror")
  • xhr: the jqXHR object used to send the AJAX request

In 99.99% of the cases all you care about is the data returned by the server. You might also be interested whether the ajax request succeeded or failed:

$.ajax({
    url: '/somescript.cgi',
    success: function(data) {
        // The request succeeded => do something with the data returned by the server
    },
    error: function() {
        // The request failed
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜