f ajax onevent,Ajax Events

Ajax Events

Ajax requests produce a number of different events that you can subscribe to. Here's a full list of the events and in what order they are triggered.

There are two types of events:

Local Events

These are callbacks that you can subscribe to within the Ajax request object, like so:

$.ajax({

beforeSend: function(){

// Handle the beforeSend event

},

complete: function(){

// Handle the complete event

}

// ......

});

Global Events

These events are triggered on the document, calling any handlers which may be listening. You can listen for these events like so:

$(document).bind("ajaxSend", function(){

$("#loading").show();

}).bind("ajaxComplete", function(){

$("#loading").hide();

});

Global events can be disabled for a particular Ajax request by passing in the global option, like so:

$.ajax({

url: "test.html",

global: false,

// ...

});

Events

This is the full list of Ajax events, and in the order in which they are triggered. The indented events are triggered for each and every Ajax request (unless a global option has been set). The ajaxStart and ajaxStop events are events that relate to all Ajax requests together.

ajaxStart (Global Event)

This event is triggered if an Ajax request is started and no other Ajax requests are currently running.

beforeSend (Local Event)

This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be.)

ajaxSend (Global Event)

This global event is also triggered before the request is run.

success (Local Event)

This event is only called if the request was successful (no errors from the server, no errors with the data).

ajaxSuccess (Global Event)

This event is also only called if the request was successful.

error (Local Event)

This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request).

ajaxError (Global Event)

This global event behaves the same as the local error event.

complete (Local Event)

This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests.

ajaxComplete (Global Event)

This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.

ajaxStop (Global Event)

This global event is triggered if there are no more Ajax requests being processed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值