Creator v2.0.10 使用短连接,构建WebMobile
在iOS设备上xhr.status = 0,Android正常
代码如下:
var xhr = new XMLHttpRequest(); xhr.open("POST", http://192.168.50.178:7082/login`, false);
xhr.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
xhr.onload = function () {
console.log("xhr.onload");
// 请求结束后,在此处写处理代码
};
xhr.onreadystatechange = ()=> { // Call a function when the state changes.
console.log(`xhr.readyState:${xhr.readyState}`);
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(`xhr.status:${xhr.status}`);
if(xhr.status >= 200 && xhr.status < 400){
var response = JSON.parse(xhr.responseText);
console.log("response:",response);
if (response["s"] === m.config.protocol.OK) {
console.log("ok");
} else {
cc.log("Server Error , Code is ", response["s"]);
}
}else{
// m.manager.global.addPublicErrorPanel(`网络错误:${xhr.status}`);
}
}
};
xhr.onerror = function (e) {
console.error("onerror:",e);
};
cc.log(`send_http:${JSON.stringify(data)}`);
xhr.send(JSON.stringify(data));`
后来用2.1.1版本构建过,在iOS设备上会出现一句:“module device.network not found”
怀疑跟iOS无法正常通讯有关,但网上没找到关于这句的相关资料,求解