From 4031b50320a241d760c7ddd07e7a97dd97d0119c Mon Sep 17 00:00:00 2001 From: Oscar Fonts Date: Fri, 4 May 2018 11:16:23 +0200 Subject: [PATCH 1/2] 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'), From d95cac5a9150575c7b5065d5dff1620107c93287 Mon Sep 17 00:00:00 2001 From: Oscar Fonts Date: Wed, 15 Aug 2018 09:25:01 +0200 Subject: [PATCH 2/2] Include HTTP status code 0 as a valid AJAX response --- src/util/ajax.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/ajax.js b/src/util/ajax.js index 9e00a136faf..34a9df6eb76 100644 --- a/src/util/ajax.js +++ b/src/util/ajax.js @@ -77,8 +77,7 @@ export const getJSON = function(requestParameters: RequestParameters, callback: callback(new Error(xhr.statusText)); }; xhr.onload = function() { - 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) { + if (((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) && xhr.response) { let data; try { data = JSON.parse(xhr.response); @@ -109,8 +108,7 @@ export const getArrayBuffer = function(requestParameters: RequestParameters, cal if (response.byteLength === 0 && xhr.status === 200) { return callback(new Error('http status 200 returned without content.')); } - 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) { + if (((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) && xhr.response) { callback(null, { data: response, cacheControl: xhr.getResponseHeader('Cache-Control'),