$.ajax({
type:
"GET"
,
url:
"Services/EFService.svc/Members"
// Play with returned data in JSON format
},
error:
(msg) {
}
});
|
全局事件是每次的Ajax请求都会触发的,它会向DOM中的所有元素广播,在上面 getScript() 示例中加载的脚本就是全局Ajax事件。全局事件可以如下定义:
$(
"#loading"
).ajaxStart(
(){
$(
this
).show();
});
我们可以在特定的请求将全局事件禁用,只要设置下 global 选项就可以了:
$.ajax({
"test.html"
global:
false
// 禁用全局Ajax事件. // ... });
下面是jQuery官方给出的完整的Ajax事件列表:
•ajaxStart (Global Event)
This event is broadcast
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,
need be.)
•ajaxSend (Global Event)
This global event is also triggered before the request is run.
•success (Local Event)
This event is only called
the request was successful (no errors from the server,no errors
with
the data).
•ajaxSuccess (Global Event)
This event is also only called
the request was successful.
•error (Local Event)
an error occurred
the request (you can never have both an error and a success callback
a request).
•ajaxError (Global Event)
This global event behaves the same as the local error event.
•complete (Local Event)
@H_404_232@
This event is called regardless of
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
there are no more Ajax requests being processed.
jQuery.ajaxSetup( options ) : 设置全局 AJAX 默认选项。
jQuery 代码:
$.ajaxSetup({
"POST"
});
$.ajax({ data: myData });