Skip to content

Commit f981228

Browse files
mikesherovkswedberg
authored andcommitted
jQuery.ajax: getAllResponseHeaders hack is no longer needed This was fixed in FF21 a while ago as well as in webkit and blink: https://bugs.webkit.org/show_bug.cgi?id=41210 https://code.google.com/p/chromium/issues/detail?id=87338 https://bugs.webkit.org/show_bug.cgi?id=76419 https://bugzilla.mozilla.org/show_bug.cgi?id=608735 confirmed using http://jsfiddle.net/xeBub/7/ in browserstack
1 parent d4ae84a commit f981228

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

entries/jQuery.ajax.xml

-33
Original file line numberDiff line numberDiff line change
@@ -301,39 +301,6 @@ jqxhr.always(function() {
301301
<p>The <code>scriptCharset</code> allows the character set to be explicitly specified for requests that use a <code>&lt;script&gt;</code> tag (that is, a type of <code>script</code> or <code>jsonp</code>). This is useful if the script and host page have differing character sets.</p>
302302
<p>The first letter in Ajax stands for "asynchronous," meaning that the operation occurs in parallel and the order of completion is not guaranteed. The <code>async</code> option to <code>$.ajax()</code> defaults to <code>true</code>, indicating that code execution can continue after the request is made. Setting this option to <code>false</code> (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive.</p>
303303
<p>The <code>$.ajax()</code> function returns the <code>XMLHttpRequest</code> object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the <code>xhr</code> option. The returned object can generally be discarded, but does provide a lower-level interface for observing and manipulating the request. In particular, calling <code>.abort()</code> on the object will halt the request before it completes.</p>
304-
<p><strong>At present</strong>, due to a bug in Firefox where <code>.getAllResponseHeaders()</code> returns the empty string although <code>.getResponseHeader('Content-Type')</code> returns a non-empty string, automatically decoding JSON CORS responses in Firefox with jQuery is not supported.</p>
305-
<p>A workaround to this is possible by overriding <code>jQuery.ajaxSettings.xhr</code> as follows:</p>
306-
<pre><code>
307-
(function() {
308-
var _super = jQuery.ajaxSettings.xhr,
309-
xhrCorsHeaders = [ "Cache-Control", "Content-Language", "Content-Type",
310-
"Expires", "Last-Modified", "Pragma" ];
311-
312-
jQuery.ajaxSettings.xhr = function() {
313-
var xhr = _super(),
314-
getAllResponseHeaders = xhr.getAllResponseHeaders;
315-
316-
xhr.getAllResponseHeaders = function() {
317-
var allHeaders = "";
318-
try {
319-
allHeaders = getAllResponseHeaders.apply( xhr );
320-
if ( allHeaders ) {
321-
return allHeaders;
322-
}
323-
} catch ( e ) {}
324-
325-
$.each( xhrCorsHeaders, function( i, headerName ) {
326-
if ( xhr.getResponseHeader( headerName ) ) {
327-
allHeaders += headerName + ": " + xhr.getResponseHeader( headerName ) + "\n";
328-
}
329-
});
330-
return allHeaders;
331-
};
332-
333-
return xhr;
334-
};
335-
})();
336-
</code></pre>
337304

338305
<h4 id="extending-ajax">Extending Ajax</h4>
339306
<p><strong>As of jQuery 1.5</strong>, jQuery's Ajax implementation includes <a href="/jQuery.ajaxPrefilter/">prefilters</a>, <a href="/jQuery.ajaxTransport/">transports</a>, and converters that allow you to extend Ajax with a great deal of flexibility.</p>

0 commit comments

Comments
 (0)