From 4031b50320a241d760c7ddd07e7a97dd97d0119c Mon Sep 17 00:00:00 2001 From: Oscar Fonts Date: Fri, 4 May 2018 11:16:23 +0200 Subject: [PATCH] Local file ajax call statuscode can be 0 on some environments (cordova iOS) --- src/util/ajax.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/ajax.js b/src/util/ajax.js index 63e96d28a60..9e00a136faf 100644 --- a/src/util/ajax.js +++ b/src/util/ajax.js @@ -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); @@ -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'),