Changeset 2005

Show
Ignore:
Timestamp:
03/18/10 11:05:57 (4 months ago)
Author:
bbinet
Message:

override-ext-ajax modify content type for non post requests anymore, r=bartvde (closes #240)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • core/trunk/geoext/lib/overrides/override-ext-ajax.js

    r1998 r2005  
    3030        request: function(method, uri, cb, data, options) { 
    3131            options = options || {}; 
     32            method = method || options.method; 
    3233            var hs = options.headers; 
    3334            if(options.xmlData) { 
     
    3637                    hs["Content-Type"] = "text/xml"; 
    3738                } 
    38                 method = (method ? method : 
    39                     (options.method ? options.method : "POST")); 
     39                method = method || "POST"; 
    4040                data = options.xmlData; 
    4141            } else if(options.jsonData) { 
     
    4444                    hs["Content-Type"] = "application/json"; 
    4545                } 
    46                 method = (method ? method : 
    47                     (options.method ? options.method : "POST")); 
     46                method = method || "POST"; 
    4847                data = typeof options.jsonData == "object" ? 
    4948                       Ext.encode(options.jsonData) : options.jsonData; 
    5049            } 
    51             // options.form or options.params means form-encoded data, so change content-type 
    52             if ((options.form || options.params) && (!hs || !hs["Content-Type"])) { 
     50            // if POST method, options.form or options.params means 
     51            // form-encoded data, so change content-type 
     52            if ((method && method.toLowerCase() == "post") && 
     53               (options.form || options.params) && 
     54               (!hs || !hs["Content-Type"])) { 
    5355                hs = hs || {}; 
    5456                hs["Content-Type"] = "application/x-www-form-urlencoded"; 
  • core/trunk/geoext/tests/lib/overrides/override-ext-ajax.html

    r2004 r2005  
    188188 
    189189        } 
     190 
     191        function test_paramsGet(t) { 
     192            t.plan(0); 
     193            /* 
     194             * Setup 
     195             */ 
     196            setup(); 
     197 
     198            var proto = OpenLayers.Request.XMLHttpRequest.prototype; 
     199            var _srh = proto.setRequestHeader;  
     200            proto.setRequestHeader = function(k, v) { 
     201                t.eq(k == "Content-Type" && v != "application/x-www-form-urlencoded", 
     202                     "Content-Type header should not be set for GET request"); 
     203            }; 
     204            Ext.Ajax.request({ 
     205                failure: function(response) { }, 
     206                method: 'GET', 
     207                success: function(response) { }, 
     208                params: { xx: 'xx', yy: 'yy'}, 
     209                url: 'foo.php' 
     210            }); 
     211            proto.setRequestHeader = _srh; 
     212 
     213            /* 
     214             * Teardown 
     215             */ 
     216            teardown(); 
     217        } 
    190218    </script> 
    191219  <body>