-
Notifications
You must be signed in to change notification settings - Fork 260
Fix incorrect override code for cors headers in firefox #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]; | ||
|
|
||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if ( allHeaders ) { | ||
| return allHeaders; | ||
| } | ||
| } catch (e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| $( xhrCorsHeaders ).each(function (i, headerName) { | ||
| if ( xhr.getResponseHeader( headerName ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| allHeaders += headerName + ": " + xhr.getResponseHeader( headerName ) + "\n"; | ||
| } | ||
| }); | ||
| return allHeaders; | ||
| }); | ||
| }; | ||
| }; | ||
|
|
||
| return xhr; | ||
| }; | ||
| return xhr; | ||
| }; | ||
| })(); | ||
| </code></pre> | ||
|
|
||
| <h4 id="extending-ajax">Extending Ajax</h4> | ||
|
|
||
There was a problem hiding this comment.
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" ];