jQuery.ajaxSetup(options)


version 1.1 以降

解説

Ajax通信で使用される共通設定を行います。jQuery内部で保持している初期設定値を上書きします。

ここで設定された内容は、全てのAjax通信で使用されます。 但し、jQuery.ajax(settings) 等で実行時に指定したものは、その通信に限り指定した値が使用されます。

引数

  • options : リクエストのパラメータ。キーと値のハッシュ。
    jQuery.ajax(settings)を参照してください。

初期設定値

jquery-1.4.2.js (Uncompressed) line4934-4969から抜粋
ajaxSettings: {
    url: location.href,
    global: true,
    type: "GET",
    contentType: "application/x-www-form-urlencoded",
    processData: true,
    async: true,
    /*
    timeout: 0,
    data: null,
    username: null,
    password: null,
    traditional: false,
    */
    // Create the request object; Microsoft failed to properly
    // implement the XMLHttpRequest in IE7 (can't request local files),
    // so we use the ActiveXObject when it is available
    // This function can be overriden by calling jQuery.ajaxSetup
    xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ?
        function() {
            return new window.XMLHttpRequest();
        } :
        function() {
            try {
                return new window.ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {}
        },
    accepts: {
        xml: "application/xml, text/xml",
        html: "text/html",
        script: "text/javascript, application/javascript",
        json: "application/json, text/javascript",
        text: "text/plain",
        _default: "*/*"
    }
},

jQuery.ajaxSetup(options)の内部動作

内部的には、上記のjQuery.ajaxSettingsに設定情報が保持されています。
jQuery.ajaxSetup(options)は、以下のようにして指定された値で上書きしているだけです。

jquery-1.4.2.js (Uncompressed) line4930-4932から抜粋
ajaxSetup: function( settings ) {
    jQuery.extend( jQuery.ajaxSettings, settings );
},