luci-base: xhr.js: decode JSON for POST requests as well
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
9ead1e29a6
commit
98217f8f8d
1 changed files with 11 additions and 8 deletions
|
@ -65,12 +65,8 @@ XHR = function()
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
var json = null;
|
var json = null;
|
||||||
if (xhr.getResponseHeader("Content-Type") == "application/json") {
|
if (xhr.getResponseHeader("Content-Type") == "application/json") {
|
||||||
try {
|
try { json = JSON.parse(xhr.responseText); }
|
||||||
json = JSON.parse(xhr.responseText);
|
catch(e) { json = null; }
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
json = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(xhr, json, Date.now() - ts);
|
callback(xhr, json, Date.now() - ts);
|
||||||
|
@ -90,8 +86,15 @@ XHR = function()
|
||||||
|
|
||||||
xhr.onreadystatechange = function()
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (xhr.readyState == 4)
|
if (xhr.readyState == 4) {
|
||||||
callback(xhr, null, Date.now() - ts);
|
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);
|
xhr.open('POST', url, true);
|
||||||
|
|
Loading…
Reference in a new issue