in my ajax call the responseHeader('Location')
is FF always empty. Can anybody help me? By the way it is a CORS.
$.ajax({
url: VIDEOS_UPLOAD_SERVICE_URL,
method: 'POST',
contentType: 'application/json',
headers: {
Authorization: 'Bearer ' + accessToken,
'x-upload-content-length': file.size,
'x-upload-content-type': file.type
},
data: JSON.stringify(metadata)
}).done(function(data, textStatus, jqXHR) {
resumableUpload({
url: jqXHR.getResponseHeader('Location'),
file: file,
start: 0
});
});
You can fix this on the server site of the code by setting the headers:
Access-Control-Expose-Headers: Location
That will tell the firefox browser to allow the cross-domain reading of the Location: header.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS?redirectlocale=en-US&redirectslug=HTTP_access_control#Access-Control-Expose-Headers
Looks like it's a bug in Firefox/jQuery: http://bugs.jquery.com/ticket/11624
Looks like it may only affect certain versions of Firefox/jQuery, and there is a patch that may resolve it. From the bug tracker another solution was posted too:
define("jquery-cors-patch", ["jquery"], function ($) {
// workaround for Firefox CORS bug - see http://bugs.jquery.com/ticket/10338
var _super = $.ajaxSettings.xhr;
$.ajaxSetup({
xhr: function() {
var xhr = _super();
var getAllResponseHeaders = xhr.getAllResponseHeaders;
xhr.getAllResponseHeaders = function() {
var allHeaders = getAllResponseHeaders.call(xhr);
if (allHeaders) {
return allHeaders;
}
allHeaders = "";
var concatHeader = function(i, header_name) {
if (xhr.getResponseHeader(header_name)) {
allHeaders += header_name + ": " + xhr.getResponseHeader( header_name ) + "\n";
}
};
// simple headers (fixed set)
$(["Cache-Control", "Content-Language", "Content-Type", "Expires", "Last-Modified", "Pragma"]).each(concatHeader);
// non-simple headers (add more as required)
$(["Location"] ).each(concatHeader);
return allHeaders;
};
return xhr;
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With