$.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. 使用FolderBrowserDialog组件选择文件夹

    实现效果: 知识运用: FolderBrowserDialog组件的ShowDialog方法 //弹出选择路径对话框 public DialogResult ShowDialog() 和Selecte ...

  2. Quartz 配置文件属性

    主要配置 Property Name Req'd Type Default Value org.quartz.scheduler.instanceName no string 'QuartzSched ...

  3. js调用后台,后台调用前台等方法总结

    1. javaScript函数中执行C#代码中的函数:方法一:1.首先建立一个按钮,在后台将调用或处理的内容写入button_click中;        2.在前台写一个js函数,内容为docume ...

  4. react 信用卡格式检验

    前言: 技术栈主要基于react + ant-design 描述: 填写信用卡卡号时,会自动四位空格,并格式校验判断卡种  ,这里我们业务只涉及到四种卡. 代码解析 // ant 组件自引,这里我只讲 ...

  5. java基础面试题:说说&和&&的区别

    &与&&都是逻辑与 不同的是&左右两边的判断都要进行,而&&是短路与,当&&左边条件为假则不用再判断右边条件,所以效率更高 例如,对于i ...

  6. Pots POJ - 3414 (搜索+记录路径)

    Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22688   Accepted: 9626   Special J ...

  7. 【线性基 集合hash】uoj#138. 【UER #3】开学前的涂鸦

    还需要加强分析题目特殊性质,设计对应特殊算法,少想多写大力dfs剪枝不要管MLETLE直接上的能力 红包是一个有艺术细胞的男孩子. 红包由于NOI惨挂心情不好,暑假作业又多,于是他开始在作业本上涂鸦. ...

  8. 【Django】Django中的模糊查询以及Q对象的简单使用

    Django中的模糊查询: 需要做一个查找的功能,所以需要使用到模糊查询. 使用方法是:字段名加上双下划线跟上contains或者icontains,icontains和contains表示是否区分大 ...

  9. 二十四、MySQL ALTER命令

    MySQL ALTER命令 当我们需要修改数据表名或者修改数据表字段时,就需要使用到MySQL ALTER命令. 开始本章教程前让我们先创建一张表,表名为:testalter_tbl. root@ho ...

  10. ASP.NET Core模块化前后端分离快速开发框架介绍之1、开篇

    源码地址 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin ...