Home  >  Article  >  Web Front-end  >  jQuery parameter list collection_jquery

jQuery parameter list collection_jquery

WBOY
WBOYOriginal
2016-05-16 18:08:351268browse

参数名 

类型 

描述 

url  

String

(默认: 当前页地址) 发送请求的地址。 

type 

String

(默认: "GET") 请求方式 ("POST" 或 "GET"), 默认为 "GET"。注意:其它 HTTP 请求方法,如 PUT 和 DELETE 也可以使用,但仅部分浏览器支持。 

timeout 

Number

设置请求超时时间(毫秒)。此设置将覆盖全局设置。 

async  

Boolean

(默认: true) 默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。 

beforeSend  

Function

发送请求前可修改 XMLHttpRequest 对象的函数,如添加自定义 HTTP头。XMLHttpRequest 对象是唯一的参数。

function (XMLHttpRequest) {

  this; // the options for this ajax request

}

cache  

Boolean

(默认: true) jQuery 1.2 新功能,设置为 false 将不会从浏览器缓存中加载请求信息。 

complete  

Function

请求完成后回调函数 (请求成功或失败时均调用)。参数:XMLHttpRequest 对象,成功信息字符串。

function (XMLHttpRequest, textStatus) {

  this; // the options for this ajax request

}

contentType  

String

(默认: "application/x-www-form-urlencoded") 发送信息至服务器时内容编码类型。默认值适合大多数应用场合。 

data

Object,
String

发送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在URL 后。查看 processData 选项说明以禁止此自动转换。必须为Key/Value 格式。如果为数组,jQuery 将自动为不同值对应同一个名称。如 {foo:["bar1", "bar2"]} 转换为 '&foo=bar1&foo=bar2'。

dataType

String

预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包MIME 信息返回 responseXML 或 responseText,并作为回调函数参数传递,可用值:

"xml": 返回 XML 文档,可用 jQuery 处理。

"html": 返回纯文本 HTML 信息;包含 script 元素。

"script": 返回纯文本 JavaScript 代码。不会自动缓存结果。

"json": 返回 JSON 数据 。

"jsonp": JSONP 格式。使用 JSONP 形式调用函数时,如 "myurl?callback=?" jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。

error

Function

(默认: 自动判断 (xml 或 html)) 请求失败时将调用此方法。这个方法有三个参数:XMLHttpRequest 对象,错误信息,(可能)捕获的错误对象。

function (XMLHttpRequest, textStatus, errorThrown) {

  // 通常情况下textStatus和errorThown只有其中一个有值

  this; // the options for this ajax request

}

global

Boolean

(Default: true) Whether to trigger global AJAX events. Setting to false will not trigger global AJAX events such as ajaxStart or ajaxStop. Can be used to control different Ajax events

ifModified

Boolean

(Default: false) Only get new data when the server data changes. Use HTTP packet Last-Modified header information to determine.

processData

Boolean

(Default: true) By default, the data sent will be converted to an object (technically not a string) to match the default content type "application/x-www-form-urlencoded". If you want to send DOM tree information or other information that you do not want to convert, please set to false.

success

Function

Callback function after the request is successful. This method has two parameters: the server returns data and returns status

function (data, textStatus) {

// data could be xmlDoc, jsonObj, html, text, etc...

this; // the options for this ajax request

}

There are several Ajax event parameters here: beforeSend , success , complete, error. We can define these events to handle each of our Ajax requests well. Note that this in these Ajax events all points to the option information of the Ajax request (please refer to the picture of this when talking about the get() method).
Please read the above parameter list carefully. If you want to use jQuery for Ajax development, you must be familiar with these parameters.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn