jquery - 有没有办法获取 $.ajax 的默认对象

标签 jquery

是否可以获得与 $.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
    }
},

关于jquery - 有没有办法获取 $.ajax 的默认对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6863855/

相关文章:

javascript - window.self.close() 不起作用

jquery - 修改显示/隐藏功能只缩放宽度,不缩放高度?

javascript - 使用 JSON 文件中的数据动态创建元素

javascript - economist.com 如何实现他们的粘性 header ?查询?

javascript - 为什么存在以及如何从页面 [Img inside] 中删除此空白区域

javascript - 为每个 div 创建随机顶部、右侧

javascript - 使用 jQuery 选择器选择 JavaScript 数组元素项

jQuery jqXHR - 取消链式调用,触发错误链

javascript - 将变量日期与 if/else 语句中的 Date(dateString) 进行比较

javascript - 使用 jquery 或 javascript 在文本框中获取 cookie 值