Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

XHR API ignores the async argument #417

Closed
sankargorthi opened this issue Oct 4, 2012 · 11 comments
Closed

XHR API ignores the async argument #417

sankargorthi opened this issue Oct 4, 2012 · 11 comments

Comments

@sankargorthi
Copy link

When an XHR.open call is made with async ===false, the API ignores it and returns the http event queue object anyway.

This can be experienced when trying to call dojo.require in dojo 1.5.2. This causes the request to be interpreted as a failure (dojo expects the request to be synchronous).

@assaf
Copy link
Owner

assaf commented Oct 5, 2012

There's no support for sync XHR and never will be.

On Thursday, October 4, 2012 at 3:07 PM, sankargorthi wrote:

When an XHR.open call is made with async = ==false, the API ignores it and returns the http event queue object anyway.
This can be experienced when trying to call dojo.require in dojo 1.5.2. This causes the request to be interpreted as a failure (dojo expects the request to be synchronous).


Reply to this email directly or view it on GitHub (#417).

@sankargorthi
Copy link
Author

That's too bad. I really like zombie and I've been trying to hack the code locally to load our company's application using dojo 1.5.2 (am stuck with using that version as it's an enterprise application).

Could you give me any pointers on where I could propagate the sync flag to? I see that the request goes to the EventQueue.prototype.http({
...
this.browser.resource._makeRequest
...
})

_makeRequest seems to be making a call to Request ... (that's as far as I've got...). Will keep digging. But any pointers would be extremely helpful.

@assaf
Copy link
Owner

assaf commented Oct 5, 2012

It's a fairly complex hack because XHR sync has to block other JavaScript and resources from loading (also, why it's recommended to not use it).

On Thursday, October 4, 2012 at 7:21 PM, sankargorthi wrote:

That's too bad. I really like zombie and I've been trying to hack the code locally to load our company's application using dojo 1.5.2 (am stuck with using that version as it's an enterprise application).
Could you give me any pointers on where I could propagate the sync flag to? I see that the request goes to the EventQueue.prototype.http({
...
this.browser.resource._makeRequest
...
})
_makeRequest seems to be making a call to Request ... (that's as far as I've got...). Will keep digging. But any pointers would be extremely helpful.


Reply to this email directly or view it on GitHub (#417 (comment)).

@sankargorthi
Copy link
Author

I understand. However, I'm stuck with using the dojo library and a UI framework that does make a lot of sync requests (we're working on moving them to async, but it'll take some time). In the mean time, I would like to use Cucumber to write test cases and Zombie to visit the pages in the test case implementation as I find them to be the best long term solution to testing our application.

I'll work some more on trying to support async==false operations on XHR.open on the fork I've created: https://github.com/sankargorthi/zombie

Any comments or suggestions are greatly appreciated and desperately needed.

@liamks
Copy link

liamks commented Dec 11, 2012

I'm writing this mainly for the benefit of others in a similar situation. I'm using Backbone Boilerplate which makes synchronous AJAX requests to grab html template files. The result is I can't test the 'dev' version of my app, and must compile the templates into the JST object prior to testing.

@cmtonkinson
Copy link
Contributor

Just to throw a note in, @assaf, a fairly complex hack yes, but technically feasible? As @liamks mentions with Boilerplate, another great example is the use of LESS. Which also by default makes use of sync requests. Suppose someone submitted a patch?

@assaf
Copy link
Owner

assaf commented Mar 14, 2013

You need to block the JS runtime while the XHR request is executing. It may be possible with native C code.

On Thu, Mar 14, 2013 at 10:09 AM, Chris notifications@github.com wrote:

Just to throw a note in, @assaf, a fairly complex hack yes, but technically feasible? As @liamks mentions with Boilerplate, another great example is the use of LESS. Which also by default makes use of sync requests.

Reply to this email directly or view it on GitHub:
#417 (comment)

@ucarbehlul
Copy link

I've forked the project and added some code for supporting sync xhr. It basically does not queue the callbacks but call them directly. It seems to be working for me, implementation has become a little hacky tough. Anyone needing this feature can have a look.

https://github.com/ucarbehlul/zombie

@ericminio
Copy link
Contributor

Hi @assaf
Will you share what you think about @ucarbehlul implementation ?

@assaf
Copy link
Owner

assaf commented Dec 11, 2013

@ericminio it doesn't return XHR response synchronously, so the only way it could work is if you set async = false, but actually handle the response asynchronously, in which case why not handle the response asynchronoulsy to begin with?

And if you handle the response synchronously, good luck figuring out why Zombie says there's a response, but you can't use it.

@asci
Copy link

asci commented Jan 2, 2014

It's a pity that zombie will never support basic browser functionality. I wanted to use it to tests, but I simulate fileReadSync for ejs with $.ajax({async: false})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants