复制代码 代码如下: $.ajax({ type: "GET", url: "Services/EFService.svc/Members", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { // Play with returned data in JSON format }, error: function (msg) { alert(msg); } });
下面是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, 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. jQuery.ajaxSetup( options ) : 设置全局 AJAX 默认选项。 设置 AJAX 请求默认地址为 "/xmlhttp/",禁止触发全局 AJAX 事件,用 POST 代替默认 GET 方法。其后的 AJAX 请求不再设置任何选项参数。 jQuery 代码: 复制代码 代码如下: $.ajaxSetup({ url: "/xmlhttp/", global: false, type: "POST" }); $.ajax({ data: myData });