1
我在node.js中写了一个HTTP服务器科尔多瓦/ PhoneGap的&node.js的:XMLHttpRequest的返回状态0
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/');
这应该从一个的PhoneGap /科尔多瓦应用服务请求:
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)
}
在config.xml中我有
<access origin=".*" />
请求返回的readyState 4也是0状态时,你会期望一个200人有一个线索?