From 98217f8f8dd1835824405d5bf3ceb95dd8f40032 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 27 Jul 2018 13:23:58 +0200 Subject: [PATCH] luci-base: xhr.js: decode JSON for POST requests as well Signed-off-by: Jo-Philipp Wich --- .../htdocs/luci-static/resources/xhr.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/xhr.js b/modules/luci-base/htdocs/luci-static/resources/xhr.js index 62b525ebb..25a90e725 100644 --- a/modules/luci-base/htdocs/luci-static/resources/xhr.js +++ b/modules/luci-base/htdocs/luci-static/resources/xhr.js @@ -65,12 +65,8 @@ XHR = function() if (xhr.readyState == 4) { var json = null; if (xhr.getResponseHeader("Content-Type") == "application/json") { - try { - json = JSON.parse(xhr.responseText); - } - catch(e) { - json = null; - } + try { json = JSON.parse(xhr.responseText); } + catch(e) { json = null; } } callback(xhr, json, Date.now() - ts); @@ -90,8 +86,15 @@ XHR = function() xhr.onreadystatechange = function() { - if (xhr.readyState == 4) - callback(xhr, null, Date.now() - ts); + if (xhr.readyState == 4) { + var json = null; + if (xhr.getResponseHeader("Content-Type") == "application/json") { + try { json = JSON.parse(xhr.responseText); } + catch(e) { json = null; } + } + + callback(xhr, json, Date.now() - ts); + } } xhr.open('POST', url, true); -- 2.25.1