themes/base: add json decoding to xhr.js
[project/luci.git] / themes / base / htdocs / luci-static / resources / xhr.js
index 7e2e3b0..9ce3026 100644 (file)
@@ -56,8 +56,18 @@ XHR = function()
 
                xhr.onreadystatechange = function()
                {
+                       var json = null;
+                       if( xhr.getResponseHeader("Content-Type") == "application/json" ) {
+                               try {
+                                       json = eval('(' + xhr.responseText + ')');
+                               }
+                               catch(e) {
+                                       json = null;
+                               }
+                       }
+
                        if( xhr.readyState == 4 ) {
-                               callback( xhr );
+                               callback( xhr, json );
                        }
                }