环境信息:
- Creator 版本号:v1.5.2
- 目标平台:iOS,系统版本10.3.1
按creator提示,创建了一个TypeScript的模板项目,主界面添加按钮,点击后发送xhr请求。在web测一切正常,iOS上不会进回调函数。求解。
代码如下:
onButtonClick() {
cc.log('do fetch');
const url = 'http://www.mocky.io/v2/59883b7b2700008800afee3b'
var xhr = cc.loader.getXMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
cc.log(xhr.responseText);
}
};
xhr.onload = function () {
cc.log('onload')
}
xhr.onloadend = function () {
cc.log('onloadend')
}
xhr.onloadstart = function () {
cc.log('onloadstart')
}
xhr.onabort = function () {
cc.log('onabort')
}
xhr.onerror = function () {
cc.log('onerror')
}
xhr.send(null);
}
Web上运行,console log如下:
do fetch
onloadstart
{ "hello": "cocos" }
onload
onloadend
iOS上运行日志如下:
do fetch
[XMLHttpRequest] GET http://www.mocky.io/v2/59883b7b2700008800afee3b
In the constructor of HttpClient!
2017-08-07 18:14:20.094 hello_world-mobile[98964:12398677] Starting to load http://www.mocky.io/v2/59883b7b2700008800afee3b
2017-08-07 18:14:20.811 hello_world-mobile[98964:12398677] Received response from request to url http://www.mocky.io/v2/59883b7b2700008800afee3b
然后没任何日志了