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

loc*_*zak 6 jquery

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

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

{
    global:true,
    headers:{},
    ifModified:false,
    type:"GET",
    url:"the current page url",
    etc....
}
Run Code Online (Sandbox Code Playgroud)

Tom*_*han 8

从查看源代码,我相信(当前)默认值可以找到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
    }
},
Run Code Online (Sandbox Code Playgroud)