summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-07-27 13:23:58 +0200
committerJo-Philipp Wich <jo@mein.io>2018-07-27 14:07:23 +0200
commit98217f8f8dd1835824405d5bf3ceb95dd8f40032 (patch)
treec6e6173a295ec9014d1fc445565b41a4c73e2dbb /modules
parent9ead1e29a6404c5ba3a438a3f8a68b6a3dcaee3f (diff)
luci-base: xhr.js: decode JSON for POST requests as well
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/xhr.js19
1 files 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 62b525ebb0..25a90e7254 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);