jquery – 有没有办法获得$.ajax的默认对象

是否可以获得与$.ajax函数关联的所有默认值.

所以它会返回这样的东西:

{
    global:true,
    headers:{},
    ifModified:false,
    type:"GET",
    url:"the current page url",
    etc....
}
从查看 source code,我相信(当前)默认值可以在jQuery.ajaxSettings中找到,当然也可以作为$.ajaxSettings使用.所以如果你没有改变它们,你应该能够从那里获得它们.

请注意,如果您更改了它们,例如使用$.ajaxSetup实用程序方法,您将获得您创建的新默认值,而不是jQuery库中的固有默认值.

另外看一下源代码,默认情况如下:

ajaxSettings: {
    url: ajaxLocation,
    isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
    global: true,
    type: "GET",
    contentType: "application/x-www-form-urlencoded",
    processData: true,
    async: true,
    /*
    timeout: 0,
    data: null,
    dataType: null,
    username: null,
    password: null,
    cache: null,
    traditional: false,
    headers: {},
    */

    accepts: {
        xml: "application/xml, text/xml",
        html: "text/html",
        text: "text/plain",
        json: "application/json, text/javascript",
        "*": "*/*"
    },

    contents: {
        xml: /xml/,
        html: /html/,
        json: /json/
    },

    responseFields: {
        xml: "responseXML",
        text: "responseText"
    },

    // List of data converters
    // 1) key format is "source_type destination_type" (a single space in-between)
    // 2) the catchall symbol "*" can be used for source_type
    converters: {

        // Convert anything to text
        "* text": window.String,

        // Text to html (true = no transformation)
        "text html": true,

        // Evaluate text as a json expression
        "text json": jQuery.parseJSON,

        // Parse text as xml
        "text xml": jQuery.parseXML
    }
},
相关文章
相关标签/搜索