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 7e2e3b090b67ec4adf73d1de96e6b9b5fdb52450..9ce302683c466f26dda8610e5e043b9503f72f0c 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 );
                        }
                }