I am trying to fix a javascript window
-element problem.
I've already did the classic:
npm install jQuery
npm update
Then, in 'server.js' file at line 1
var $ = require('jQuery');
On my Ubuntu this code works good, no problems, and the application goes ahead. On Windows 7 there is a monster i can't fight with.
Writing node server.js
on my cmd (with Admin Rights), I see this msg:
I just couldn't take the reason of this: window.XMLHttpRequest is undefined
. I am a curious person, so i discover where window.XMLHttpRequest
is initialized and who/what works for this:
At line 8 of http://github.com/coolaj86/node-jquery/blob/master/lib/node-jquery.js.
window.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
Why is not doing its job?
https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js here is the xmlhttprequest code.
Solution:
- install python from 2.5.0 to 3.0.0 version (free)
- install Visual Express 2010 or later (free)
you need to install xmlhttprequest module with npm :
npm install xmlhttprequest
but normally, it is a browser only object, you should use that on the server : http://nodejs.org/docs/latest/api/http.html
you need to manually patch your node_module/jquery/lib/node-jquery.js
file!
Change these lines (around line 4 and 5) from:
if(window == null ) {
window = require('jsdom').jsdom().createWindow();
...
to:
if (!window || !window.document) {
window = require('jsdom').createWindow();
window.document = require('jsdom').jsdom();
...