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:
parent
186228e365
commit
64e3fe9f6b
1 changed files with 11 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue