$.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. pc-要实现相隔一定时间数据排序变化一次

    有时候产品会有这种要求,就是展示的数据三天是正序的,一天是逆序的,解决是: 以某一个时间点为基准点,然后获取当前的时间,然后计算差值,分情况 //专利 JPView : function(Sorder ...

  2. 关于mongodb的日志

    mongodb的日志与profile相似,在启动mongod时 可以用verbose这个参数配置他的日志详细程度,分为一个v到5个v,其中v越多,详细度越高   mogod.conf port = d ...

  3. C/C++语言补缺 宏- extern "C"-C/C++互调

    1. 宏中的# 宏中的#的功能是将其后面的宏参数进行字符串化操作(Stringizing operator),简单说就是在它引用的宏变量的左右各加上一个双引号. 如定义好#define STRING( ...

  4. Processing入门指南

    简介 Processing 是由 MIT 媒体实验室的 Casey Reas 和 Benjamin Fry 发明的一种开源可视化编程语言.Processing为数字媒体与娱乐交互设计而创建,其目的是通 ...

  5. 交叉验证(Cross Validation)方法思想简介

      以下简称交叉验证(Cross Validation)为CV.CV是用来验证分类器的性能一种统计分析方法,基本思想是把在某种意义下将原始数据(dataset)进行分组,一部分做为训练集(train ...

  6. 魅族MX3 Flyme3.0找回手机功能支持远程拍照密码错两次自动拍照

    进入Flyme页面(http://app.meizu.com/),选择“查找手机”即可进行查找自己登记的魅族系列手机. 如果您在一个账号下登记过N多魅族系列手机,那么都是可以进行查找的,参见下图 魅族 ...

  7. 零基础快速入门SpringBoot2.0教程 (三)

    一.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...

  8. iOS开发遇到的坑之七--上传app Stroe被拒绝:The app references non-public symbols in : _UICreateCGImageFromIOSurface

    这是上学期遇到的问题了,突然查阅邮箱的时候发现了,遂在这里记录下来,希望大家以后注意这个问题 我上传App Store的时候,apple给我发的邮件原文: Dear developer, We hav ...

  9. 洛谷 P1346 电车

    这道题的关键在建图 把每一个车站看成一个点,将这个车站相连的第一个车站建立一条边权为0的边,对于它所相连的其他车站,建立边权为1的边: 这样我们可以得到一张图: 起点,终点都知道了,跑一边最短路即可 ...

  10. JavaScript 循环

    for循环:  如果您希望一遍又一遍运行相同的代码,并且每次的值都不同,那么使用循环是很方便的. 我们可以这样输出数组的值: document.write(cars[0] + "<br ...