$.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);
            }
        });
全局事件是每次的Ajax请求都会触发的,它会向DOM中的所有元素广播,在上面 getScript() 示例中加载的脚本就是全局Ajax事件。全局事件可以如下定义:
 
$("#loading").ajaxStart(function(){
 
$(this).show();
 
});
 
 
 
 
 
我们可以在特定的请求将全局事件禁用,只要设置下 global 选项就可以了:
 
$.ajax({
 
url: "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, 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 });

如果指定为 html 类型,任何内嵌的 JavaScript 都会在 HTML 作为一个字符串返回之前执行。类似地,指定 script 类型的话,也会先执行服务器端生成 JavaScript,然后再把脚本作为一个文本数据返回。

JSON 数据是一种能很方便通过 JavaScript 解析的结构化数据。如果获取的数据文件存放在远程服务器上(域名不同,也就是跨域获取数据),则需要使用 jsonp 类型。使用这种类型的话,会创建一个查询字符串参数 callback=? ,这个参数会加在请求的 URL 后面。服务器端应当在 JSON 数据前加上回调函数名,以便完成一个有效的 JSONP 请求。如果要指定回调函数的参数名来取代默认的 callback,可以通过设置 $.ajax() 的 jsonp 参数。

随机推荐

  1. IOS 拖拽事件(手势识别)

    @interface NJViewController () @property (weak, nonatomic) IBOutlet UIView *customView; @end @implem ...

  2. POJ 1065 Wooden Sticks(LIS,最少链划分)

    题意:求二维偏序的最少链划分. 用到Dilworth定理:最少链划分=最长反链.(对偶也成立,个人认为区别只是一个维度上的两个方向,写了个简单的证明 相关概念:偏序集,链,反链等等概念可以参考这里:h ...

  3. UVA 11990 ``Dynamic'' Inversion (线段树套BIT,分治)

    题目要求可转化为查询一个区间内有多少数比val大(或者小). 区间用线段树分解(logN),每个区间维护一rank树. rank可用BIT查询,往BIT里面插值,为了保证不同区间的BIT互不影响要先离 ...

  4. mongostat查看mongodb运行状态使用命令介绍

    mongostat是mongodb自带的一个用来查看mongodb运行状态的工具 使用说明 mongostat -h   字段说明 启用后的状况是这样的 insert query update del ...

  5. Python实现注册和登录

    一.注册账号需要实现的功能 1.输入:用户名,密码,密码确认 2.限制1:输入的账号和密码不能为空 3.限制2:两次输入密码必须一致 4.限制3:用户名不能重复 5.限制4:错误次数为4次 6.用字典 ...

  6. 使用ASP.NET Web API和Web API Client Gen使Angular 2应用程序的开发更加高效

    本文介绍“ 为ASP.NET Web API生成TypeScript客户端API ”,重点介绍Angular 2+代码示例和各自的SDLC.如果您正在开发.NET Core Web API后端,则可能 ...

  7. GCH文件

    GCH文件是将H文件当作CPP进行编译之后出现的结果, 在头文件进行编译后就会在文件夹中看到一个 “文件名.h.gch” 的文件. 那么在再次对gch文件进行编译的时候就会将gch当作cpp一样对待. ...

  8. js当中mouseover和mouseout多次触发(非冒泡)

    JS当中,mouseover和mouseout多次触发事件,不光是冒泡会产生,就是不冒泡,在一定条件下 ,也会产生多次触发事件: 例如下面的结构的情况下,我在class="ceng_up f ...

  9. CXF学习记录

    1 apache CXF入门 1.1 下载 官网:cxf.apache.org 下载CXF的开发包: Apache CXF = Celtix + Xfire 支持多种协议: SOAP1.1,1.2 X ...

  10. Bootstrap 附加导航(Affix)插件

    bootstrap 附加导航(Affix)插件允许某个div元素固定到页面中的某个位置.您可以打开或关闭使用该插件之间进行切换 后续再写