getXMLHttpRequest安卓真机上不能访问服务器接口 在访问时 连接的readyState 一直处于1的状态.但是在 浏览器测试时 是能够正常访问的。请问这个有办法解决嘛! 我的代码如下
this.httpPost=function (url, params, callback) {
var xhr = cc.loader.getXMLHttpRequest();
var sendstr=JSON.stringify(params);
xhr.onreadystatechange = function () {
// cc.log(‘xhr.readyState=’+xhr.readyState+’ xhr.status=’+xhr.status);
if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
var respone = xhr.responseText;
callback(JSON.parse(respone));
}else{
// callback(-1);
cc.find(“Canvas/username/editbox”).getComponent(cc.EditBox).string=xhr.readyState;
}
};
xhr.open("POST", rootPath+url, true);
if (cc.sys.isNative) {
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
}
xhr.setRequestHeader("Content-Type","application/json");
// note: In Internet Explorer, the timeout property may be set only after calling the open()
// method and before calling the send() method.
xhr.timeout = 5000;// 5 seconds for timeout
xhr.send(sendstr);
}