控制台有打印以下语句,但是没有进入ontimeout回调函数里面,这块的api是有调整吗
2017-12-05 21:05:22.777323+0800 PB-mobile[30326:2823706] NSURLConnection finished with error - code -1001
Response failed, error buffer: The request timed out.
2017-12-05 21:05:22.790239+0800 PB-mobile[30326:2823428] Task <5ACBF608-95C9-4B62-A3C1-DE12A4A23964>.<0> HTTP load failed (error code: -999 [1:89])
2017-12-05 21:06:23.191536+0800 PB-mobile[30326:2823899] TIC Read Status [4:0x1c0361680]: 1:57
XMLHttpRequest_finalize, 0x10334bdc0 …
XMLHttpRequest_finalize, 0x103453ed0 …
请求的代码如下:
sendRequest : function(path,data,success, error, timeout,time){
if(!data) {
data = {};
}
var xhr = cc.loader.getXMLHttpRequest();
xhr.timeout = time ? time : 3000;
var str = "?";
for(var k in data){
if(str != "?"){
str += "&";
}
str += k + "=" + encodeURIComponent(data[k]);
}
var requestURL = HTTP.url + path + str;
if(path.indexOf('http:')>=0) {
requestURL = path;
}
console.log("RequestURL:" + requestURL);
xhr.open("GET",requestURL, true);
if (cc.sys.isNative){
xhr.setRequestHeader("Accept-Encoding","gzip,deflate","text/html;charset=UTF-8");
}
xhr.onreadystatechange = function() {
if(xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)){
try {
console.log(xhr.responseText);
var ret = JSON.parse(xhr.responseText);
success && success(ret);
} catch (e) {
error && error();
}
}
};
//超时回调
xhr.ontimeout = function(event){
console.log('超时啦' );
timeout && timeout();
};
xhr.onerror = function(event){
error && error();
};
xhr.send();
return xhr;
}