Replace the no-op XMLHttpRequest with node-XMLHttpRequest #380

Closed
leonyu opened this Issue Dec 27, 2011 · 9 comments

Projects

None yet

3 participants

@leonyu
leonyu commented Dec 27, 2011

The adding of a No Operation XMLHttpRequest is causing other add-on to break, namely node-jquery's $.ajax() functionality. Please remove this implementation or replace it with a node-XMLHttpRequest implementation.

@leonyu
leonyu commented Dec 29, 2011

To reproduce:


then create and run a JS file with the following content:


(function(){
        var window = require('jsdom').jsdom().createWindow();
        var $ = require('jquery').create(window);
        $.support.cors = true;// enable cross-domain requests
        $.get('http://www.yahoo.com/').done(function(){console.log('success');}).fail(function(){console.log('failure')});
})();

(function(){
        var window = require('jsdom').jsdom().createWindow();
        window.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
        var $ = require('jquery').create(window);
        $.support.cors = true;// enable cross-domain requests
        $.get('http://www.yahoo.com/').done(function(){console.log('success');}).fail(function(){console.log('failure')});
})();

The first item fails because node-jquery uses the XMLHttpRequest implemented in jsdom (which is a noOp). The second item succeeds as I have replaced it explicitly with a working wrapper.

@dai-shi dai-shi referenced this issue in angular/angular.js Mar 11, 2013
Open

Server side rendering discussion #2104

@dai-shi
dai-shi commented Jun 25, 2013

My fork https://github.com/dai-shi/jsdom adds node-XMLHttpRequest functionality and it seems working. It keeps cookies (127.0.0.1 only) for XHR, but it's more or less a hack. Any idea to properly implement this is welcomed.

@domenic
Collaborator
domenic commented Jun 25, 2013

@dai-shi can you point us to the commit where you add node-XMLHttpRequest? My guess is that your hack will be better than what we have, so we can probably use it :)

@dai-shi
dai-shi commented Jun 25, 2013

Hm, the basic one is very simple: 6936046
After that, I added cookie passing functionality: 6936046 -> 59d865e
(How can I show commit diffs in GitHub?)
Hope it helps.

@dai-shi
dai-shi commented Jun 25, 2013

@domenic I could make the compare view: dai-shi@6936046...59d865e
By "seems working", I meant I could successfully run e2e tests in https://github.com/dai-shi/connect-prerenderer

@domenic
Collaborator
domenic commented Jul 4, 2013

@dai-shi that looks great. I'd love a pull request with that code (all in one commit). Ideally you could add a test that the XHR works, maybe spinning up a server like in the test "redirected_url_equal_to_location_href" in test/jsdom/index.js. Then you could do an XHR from a jsdom window against that server and make sure it gets results.

@dai-shi
dai-shi commented Jul 5, 2013

@domenic OK, I will try it next week.
Let me know if you have any thought about cookie passing in the XHR.

@domenic
Collaborator
domenic commented Jul 5, 2013

I'm all for cookie passing in XHR! Happy to include that code too.

@dai-shi
dai-shi commented Jul 22, 2013

@domenic I think you can close this issue now.

@domenic domenic closed this Jul 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment