Skip to content

Commit

Permalink
Local file ajax call statuscode can be 0 on some environments (cordov…
Browse files Browse the repository at this point in the history
…a iOS)
  • Loading branch information
oscarfonts committed Jul 25, 2018
1 parent b446917 commit 4031b50
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export const getJSON = function(requestParameters: RequestParameters, callback:
callback(new Error(xhr.statusText));
};
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300 && xhr.response) {
const isFile = xhr.responseURL && xhr.responseURL.indexOf("file://") === 0; // If loading a local file, don't check status code
if (((xhr.status >= 200 && xhr.status < 300) || isFile) && xhr.response) {
let data;
try {
data = JSON.parse(xhr.response);
Expand Down Expand Up @@ -108,7 +109,8 @@ export const getArrayBuffer = function(requestParameters: RequestParameters, cal
if (response.byteLength === 0 && xhr.status === 200) {
return callback(new Error('http status 200 returned without content.'));
}
if (xhr.status >= 200 && xhr.status < 300 && xhr.response) {
const isFile = xhr.responseURL && xhr.responseURL.indexOf("file://") === 0; // If loading a local file, don't check status code
if (((xhr.status >= 200 && xhr.status < 300) || isFile) && xhr.response) {
callback(null, {
data: response,
cacheControl: xhr.getResponseHeader('Cache-Control'),
Expand Down

0 comments on commit 4031b50

Please sign in to comment.