luci-base: xhr.js: decode JSON for POST requests as well

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 98217f8f8d)
This commit is contained in:
Jo-Philipp Wich 2018-07-27 13:23:58 +02:00
parent 186228e365
commit 64e3fe9f6b

View file

@ -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);