非常教程

jQuery参考手册

jQuery ajaxSetup() 方法

jQuery ajaxSetup() 方法

jQuery ajaxSetup() 方法

jQuery ajaxSetup() 方法

jQuery AJAX 方法

实例

为所有 AJAX 请求设置默认 URL 和 success 函数:

$("button").click(function(){ $.ajaxSetup({ url:"demo_ajax_load.txt", success:function(result){ $("div").html(result); } }); $.ajax(); });

尝试一下 »

定义和用法

ajaxSetup() 方法为将来的 AJAX 请求设置默认值。


语法

$.ajaxSetup({name:value, name:value, ... })

该参数为带有一个或多个名称/值对的 AJAX 请求规定设置。

下面的表格中列出了可能的名称/值:

名称 值/描述
async 布尔值,表示请求是否异步处理。默认是 true。
beforeSend(xhr) 发送请求前运行的函数。
cache 布尔值,表示浏览器是否缓存被请求页面。默认是 true。
complete(xhr,status) 请求完成时运行的函数(在请求成功或失败之后均调用,即在 success 和 error 函数之后)。
contentType 发送数据到服务器时所使用的内容类型。默认是:"application/x-www-form-urlencoded"。
context 为所有 AJAX 相关的回调函数规定 "this" 值。
data 规定要发送到服务器的数据。
dataFilter(data,type) 用于处理 XMLHttpRequest 原始响应数据的函数。
dataType 预期的服务器响应的数据类型。
error(xhr,status,error) 如果请求失败要运行的函数。
global 布尔值,规定是否为请求触发全局 AJAX 事件处理程序。默认是 true。
ifModified 布尔值,规定是否仅在最后一次请求以来响应发生改变时才请求成功。默认是 false。
jsonp 在一个 jsonp 中重写回调函数的字符串。
jsonpCallback 在一个 jsonp 中规定回调函数的名称。
password 规定在 HTTP 访问认证请求中使用的密码。
processData 布尔值,规定通过请求发送的数据是否转换为查询字符串。默认是 true。
scriptCharset 规定请求的字符集。
success(result,status,xhr) 当请求成功时运行的函数。
timeout 设置本地的请求超时时间(以毫秒计)。
traditional 布尔值,规定是否使用参数序列化的传统样式。
type 规定请求的类型(GET 或 POST)。
url 规定发送请求的 URL。默认是当前页面。
username 规定在 HTTP 访问认证请求中使用的用户名。
xhr 用于创建 XMLHttpRequest 对象的函数。


jQuery ajaxSetup() 方法

更多实例

规定 AJAX 请求的错误处理程序
如何使用错误设置来规定 AJAX 请求的错误处理程序。


jQuery ajaxSetup() 方法

jQuery AJAX 方法

jQuery ajaxSetup() 方法

jQuery目录

1.jQuery 教程
2.jQuery 简介
3.jQuery 安装
4.jQuery 语法
5.jQuery 选择器
6.jQuery 效果 – 隐藏和显示
7.jQuery 事件
8.jQuery 效果 – 滑动
9.jQuery 效果 – 淡入淡出
10.jQuery 链
11.jQuery Callback 方法
12.jQuery 效果 – 停止动画
13.jQuery 效果 – 动画
14.jQuery 遍历 – 后代
15.jQuery 遍历 – 祖先
16.jQuery 遍历
17.jQuery 尺寸
18.jQuery css() 方法
19.jQuery 获取并设置 CSS 类
20.jQuery 删除元素
21.jQuery 添加元素
22.jQuery 设置内容和属性
23.jQuery 获取内容和属性
24.jQuery 实例
25.jQuery noConflict() 方法
26.jQuery – AJAX get() 和 post() 方法
27.jQuery – AJAX load() 方法
28.jQuery AJAX 简介
29.jQuery 遍历 – 过滤
30.jQuery 遍历 – 同胞(siblings)
31.jQuery :even 选择器
32.jQuery :last 选择器
33.jQuery :first 选择器
34.jQuery 多个元素选择器
35.jQuery element 选择器
36.jQuery 多个类选择器
37.jQuery .class 选择器
38.jQuery #id 选择器
39.jQuery * 选择器
40.jQuery :only-child 选择器
41.jQuery :nth-last-of-type() 选择器
42.jQuery :nth-of-type() 选择器
43.jQuery :nth-last-child() 选择器
44.jQuery :nth-child() 选择器
45.jQuery :last-of-type 选择器
46.jQuery :last-child 选择器
47.jQuery :first-of-type 选择器
48.jQuery :first-child 选择器
49.jQuery :odd 选择器
50.jQuery :header 选择器
51.jQuery :not() 选择器
52.jQuery :lt() 选择器
53.jQuery :gt() 选择器
54.jQuery :eq() 选择器
55.jQuery element ~ siblings 选择器
56.jQuery element + next 选择器
57.jQuery 父后代选择器
58.jQuery parent > child 选择器
59.jQuery :only-of-type 选择器
60.jQuery :lang() 选择器
61.jQuery :root 选择器
62.jQuery :visible 选择器
63.jQuery :hidden 选择器
64.jQuery :parent 选择器
65.jQuery :empty 选择器
66.jQuery :has() 选择器
67.jQuery :contains() 选择器
68.jQuery :focus 选择器
69.jQuery :animated 选择器
70.jQuery :input 选择器
71.jQuery [attribute*=value] 选择器
72.jQuery [attribute~=value] 选择器
73.jQuery [attribute^=value] 选择器
74.jQuery [attribute|=value] 选择器
75.jQuery [attribute$=value] 选择器
76.jQuery [attribute!=value] 选择器
77.jQuery [attribute=value] 选择器
78.jQuery [attribute] 选择器
79.jQuery :image 选择器
80.jQuery :button 选择器
81.jQuery :reset 选择器
82.jQuery :submit 选择器
83.jQuery :checkbox 选择器
84.jQuery :radio 选择器
85.jQuery :password 选择器
86.jQuery :text 选择器
87.jQuery dblclick() 方法
88.jQuery click() 方法
89.jQuery change() 方法
90.jQuery blur() 方法
91.jQuery bind() 方法
92.jQuery :checked 选择器
93.jQuery :selected 选择器
94.jQuery :disabled 选择器
95.jQuery :enabled 选择器
96.jQuery :file 选择器
97.jQuery event.namespace 属性
98.jQuery event.isPropagationStopped() 方法
99.jQuery event.isImmediatePropagationStopped() 方法
100.jQuery event.isDefaultPrevented() 方法