本文共 1071 字,大约阅读时间需要 3 分钟。
项目中碰到一个问题,需要在一个异步请求A的响应中再发送一个异步请求B,chrome中一切ok,但是firefoxB总是发送失败,浏览器f12开发者模式下甚至没有看到发送的请求B。
伪码如下:
this.httpAPI.A().then( resp => { if (!resp.success) { this.alertService.warning(resp.error); return; } //异步请求 this.httpAPI.B(); //页面实现跳转 windows.location.href=xxxxxx } ).catch(function () { });
后来经过鉴定,问题出在href中,我猜测B请求还未返回结果,当前页面跳转,后续结果返回,没有接收器了。修改的办法是等B请求返回后,再执行href
this.httpAPI.A().then( resp => { if (!resp.success) { this.alertService.warning(resp.error); return; } //异步请求 this.httpAPI.B().then( { //页面实现跳转 windows.location.href=xxxxxx }); } ).catch(function () { });
转载地址:http://qitwz.baihongyu.com/