themes/base: add json decoding to xhr.js
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 15 Nov 2010 14:40:28 +0000 (14:40 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 15 Nov 2010 14:40:28 +0000 (14:40 +0000)
themes/base/htdocs/luci-static/resources/xhr.js

index 7e2e3b0..9ce3026 100644 (file)
@@ -56,8 +56,18 @@ XHR = function()
 
                xhr.onreadystatechange = 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 ) {
                        if( xhr.readyState == 4 ) {
-                               callback( xhr );
+                               callback( xhr, json );
                        }
                }
 
                        }
                }