themes/base: fix error r7144, location.host already includes the port number and...
[project/luci.git] / themes / base / htdocs / luci-static / resources / xhr.js
index 9ce3026..23bf96e 100644 (file)
@@ -43,8 +43,7 @@ XHR = function()
                var xhr  = this._xmlHttp;
                var code = this._encode( data );
 
-               url = 'http://' + location.hostname +
-                       ( location.port ? ':' + location.port : '' ) + url;
+               url = location.protocol + '//' + location.host + url;
 
                if( code )
                        if( url.substr(url.length-1,1) == '&' )
@@ -56,17 +55,17 @@ 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 ) {
+                               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, json );
                        }
                }
@@ -144,6 +143,9 @@ XHR = function()
 
        this._encode = function(obj)
        {
+               obj = obj ? obj : { };
+               obj['_'] = Math.random();
+
                if( typeof obj == 'object' )
                {
                        var code = '';
@@ -152,6 +154,7 @@ XHR = function()
                        for( var k in obj )
                                code += ( code ? '&' : '' ) +
                                        k + '=' + encodeURIComponent( obj[k] );
+
                        return code;
                }