luci-base: xhr.js: fix timeout setting with IE 11
authorJo-Philipp Wich <jo@mein.io>
Sat, 28 Apr 2018 20:55:08 +0000 (22:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sat, 5 May 2018 19:16:53 +0000 (21:16 +0200)
Internet Explorer 11 requires the timeout to be applied after the open()
call, otherwise an invlaid state exception will be raised

Fixes aa6c97154 ("luci-base: extend xhr.js")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/xhr.js

index 91dcf3f..de4476c 100644 (file)
@@ -54,11 +54,11 @@ XHR = function()
                        else
                                url += '?' + code;
 
                        else
                                url += '?' + code;
 
+               xhr.open('GET', url, true);
+
                if (!isNaN(timeout))
                        xhr.timeout = timeout;
 
                if (!isNaN(timeout))
                        xhr.timeout = timeout;
 
-               xhr.open('GET', url, true);
-
                xhr.onreadystatechange = function()
                {
                        if (xhr.readyState == 4) {
                xhr.onreadystatechange = function()
                {
                        if (xhr.readyState == 4) {
@@ -92,10 +92,11 @@ XHR = function()
                                callback(xhr);
                }
 
                                callback(xhr);
                }
 
+               xhr.open('POST', url, true);
+
                if (!isNaN(timeout))
                        xhr.timeout = timeout;
 
                if (!isNaN(timeout))
                        xhr.timeout = timeout;
 
-               xhr.open('POST', url, true);
                xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                xhr.send(code);
        }
                xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                xhr.send(code);
        }