Cordova / phonegap & node.js : XMLHttpRequest returns status 0

I've written an HTTP server in node.js

var http = require('http');
http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World ' + request.url + '\n\n');
  console.log(request.url);
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');

That should serve requests from a phonegap / cordova app:

function testnodejs() {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)  {
        alert ("Your webbrowser does not support HTTP Request");
        return;
    }
    var url="http://domain.com:8124/i.t?hi=hi!";
    console.log(url);
    document.getElementById("maindiv").innerHTML = "<div id='itembrd' onClick=\"testnodejs();\"><div id='item'>Nodetest</div></div>";
    xmlHttp.open("GET", url, true)
xmlHttp.onreadystatechange=function() {
        document.getElementById("maindiv").innerHTML += xmlHttp.status + " ";
        if (xmlHttp.readyState==4) {
            console.log(xmlHttp.responseText);
            document.getElementById("maindiv").innerHTML += xmlHttp.responseText + '<br />\n';
        }
    }
    xmlHttp.send(null)
}

In config.xml I have

<access origin=".*" />

The request returns a readyState 4 but also a status of 0 when you'd expect a 200. Anyone have a clue?

So, I put this aside for a couple of days. Headed back in with fresh abandon and fixed it. The issue was at the node.js server side which doesn't return 200 but 0. That's because of allow origin. I rewrote the response header thusly:

response.writeHead(200, {
    'Content-Type': 'text/plain',
    'Access-Control-Allow-Origin' : '*'
});

and voila! tango!

Now I have a very lightweight solution for XHR requests from within cordova / phonegap apps.