[LayaAir 2.0]手机调试时http请求错误,返回Request failed Status:0
Laya版本为2.0,程序中用Laya.HttpRequest的send函数post请求一个地址,在layaair中启动浏览器,可以正常得到回复,但用layaair生成的二维码,通过手机扫描测试,send请求时,就会收到一个error事件,错误提示Request failed Status:0,但服务器却可以收到请求,请问这个怎么解决?下面是代码片段:
let hr = new Laya.HttpRequest();
hr.http.timeout = 5000;
hr.on(Laya.Event.PROGRESS, this, this.onHttpRequestProgress);
hr.once(Laya.Event.COMPLETE, this, (response)=>{
UIFactory.closeWaitBar();
this.onHttpRequestComplete(response);
if(handleOk){
handleOk(response);
}
});
hr.once(Laya.Event.ERROR, this, (e)=>{
UIFactory.closeWaitBar();
this.onHttpRequestError(e);
if(handleFail){
handleFail(e);
}
else{
UIFactory.alertConfirm(LayaWrap.creatHandlerCall(this,()=>{
UIFactory.showWaitBar(LayaWrap.creatHandlerCall(this,()=>{
this.connect(handleOk,handleFail);
}))
}), LocalTxt.getText("请求失败")+":"+e);
}
});
LogUtil.info(this.urlString,this.methodString,this.responseType,this.dataAny);
hr.send(this.urlString, this.dataAny, this.methodString, this.responseType,this.headers);
let hr = new Laya.HttpRequest();
hr.http.timeout = 5000;
hr.on(Laya.Event.PROGRESS, this, this.onHttpRequestProgress);
hr.once(Laya.Event.COMPLETE, this, (response)=>{
UIFactory.closeWaitBar();
this.onHttpRequestComplete(response);
if(handleOk){
handleOk(response);
}
});
hr.once(Laya.Event.ERROR, this, (e)=>{
UIFactory.closeWaitBar();
this.onHttpRequestError(e);
if(handleFail){
handleFail(e);
}
else{
UIFactory.alertConfirm(LayaWrap.creatHandlerCall(this,()=>{
UIFactory.showWaitBar(LayaWrap.creatHandlerCall(this,()=>{
this.connect(handleOk,handleFail);
}))
}), LocalTxt.getText("请求失败")+":"+e);
}
});
LogUtil.info(this.urlString,this.methodString,this.responseType,this.dataAny);
hr.send(this.urlString, this.dataAny, this.methodString, this.responseType,this.headers);
没有找到相关结果
已邀请:
2 个回复
nevercai
赞同来自:
你用chrome打开二维码的那个网址,按F12,查看console。就能看到报错信息了。
解决方法是在服务端,处理请求的时候加上对应的允许跨域header。具体搜索一下“跨域解决”就有。
TsubasaYeung
赞同来自: