Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync xhr request timeout #1

Closed
SergeAgeyev opened this issue Oct 12, 2017 · 2 comments
Closed

Sync xhr request timeout #1

SergeAgeyev opened this issue Oct 12, 2017 · 2 comments

Comments

@SergeAgeyev
Copy link

Hi here,

RockJs is a great framework, we use it in our projects.
However, we encountered an issue when tried to send synchronous xhr request.
I know sync xhr requests are deprecated, but we need it in one tricky point of internal project as temporary fix. It fails with exception "Timeouts cannot be set for synchronous requests made from a document.". The reason is simple: timeout is not allowed in sync requests.

So we fixed it in core/js/generic/includers.js by changing:
xhr.timeout = q.timeout;
to:
if (q.async) { xhr.timeout = q.timeout; }

Patch:

 core/js/generic/includers.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/js/generic/includers.js b/core/js/generic/includers.js
index 292afd7..c5c4951 100644
--- a/core/js/generic/includers.js
+++ b/core/js/generic/includers.js
@@ -220,7 +220,7 @@
      }
     try{xhr.open(q.type, url, q.async);}
     catch(e){onError(e, execCallbacks);};
-    xhr.timeout = q.timeout;
+    if (q.async) { xhr.timeout = q.timeout; }
     if (q.contentType != null) xhr.setRequestHeader('Content-type', q.contentType);
     if (q.xRequestedWith != null) xhr.setRequestHeader('X-Requested-With', q.xRequestedWith);
     for (var i in q.headers) xhr.setRequestHeader(String(i), String(q.headers[i]));

@w3core
Copy link
Owner

w3core commented Oct 13, 2017

Thanks a lot!
I'll fix this bug as soon as possible and let you know.

@w3core
Copy link
Owner

w3core commented Oct 13, 2017

Done! You can find these changes in the latest updates of the master branch

@w3core w3core closed this as completed Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants