locrizak
locrizak

Reputation: 12279

Is there a way to get $.ajax's default object

Is it possible to get all the defaults that are associcate with the $.ajax function.

So it would return something like this:

{
    global:true,
    headers:{},
    ifModified:false,
    type:"GET",
    url:"the current page url",
    etc....
}

Upvotes: 6

Views: 1259

Answers (2)

Tomas Aschan
Tomas Aschan

Reputation: 60644

From looking at the source code, I believe the (current) defaults are found in jQuery.ajaxSettings, of course also available as $.ajaxSettings. So if you haven't changed them, you should be able to get them from there.

Note that if you have changed them, for example using the $.ajaxSetup utility method, you'll get the new defaults you created, not the inherent ones from the jQuery library.

Also looking at the source code, it seems the defaults are the following:

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
    }
},

Upvotes: 8

robbrit
robbrit

Reputation: 17960

They are listed in the jQuery docs:

http://api.jquery.com/jQuery.ajax/

Upvotes: 0

Related Questions