Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions entries/jQuery.ajax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,29 +284,35 @@ jqxhr.always(function() { alert("second complete"); });</code></pre>
<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>
<p>A workaround to this is possible by overriding <code>jQuery.ajaxSettings.xhr</code> as follows:</p>
<pre><code>
var _super = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function () {
var xhr = _super(),
getAllResponseHeaders = xhr.getAllResponseHeaders;
(function () {
var _super = jQuery.ajaxSettings.xhr,
xhrCorsHeaders = ["Cache-Control", "Content-Language", "Content-Type", "Expires", "Last-Modified", "Pragma"];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ "Cache-Control", "Content-Language", "Content-Type", "Expires", "Last-Modified", "Pragma" ];


xhr.getAllResponseHeaders = function () {
if ( getAllResponseHeaders() ) {
return getAllResponseHeaders();
}
var allHeaders = "";
jQuery.ajaxSettings.xhr = function () {
var xhr = _super(),
getAllResponseHeaders = xhr.getAllResponseHeaders;

$( ["Cache-Control", "Content-Language", "Content-Type",
"Expires", "Last-Modified", "Pragma"] )
.each(function (i, header_name) {
if ( xhr.getResponseHeader( header_name ) ) {
allHeaders += header_name + ": " + xhr.getResponseHeader( header_name ) + "\n";
xhr.getAllResponseHeaders = function () {
var allHeaders = "";
try {
allHeaders = getAllResponseHeaders.apply(xhr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( xhr );

if ( allHeaders ) {
return allHeaders;
}
} catch (e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( e )

}

$( xhrCorsHeaders ).each(function (i, headerName) {
if ( xhr.getResponseHeader( headerName ) ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( i, headerName )

allHeaders += headerName + ": " + xhr.getResponseHeader( headerName ) + "\n";
}
});
return allHeaders;
});
};
};

return xhr;
};
return xhr;
};
})();
</code></pre>

<h4 id="extending-ajax">Extending Ajax</h4>
Expand Down