前端获取http状态码400的返回值实例

所属分类: 网络编程 / CSS/HTML 阅读数: 468
收藏 0 赞 0 分享

如下所示:

axios.get("/check_mobile_and_sent_code",{withCredentials:true,params:{mobile:formInline.mobile}}).then(res=>{
            console.log(res);
            //if(res.result==true){
              if (!this.timer) {
                this.count = this.TIME_COUNT;
                this.show = false;
                this.timer = setInterval(() => {
                  if (this.count > 0 && this.count <= this.TIME_COUNT) {
                    this.count--;
                  } else {
                    this.show = true;
                    clearInterval(this.timer);
                    this.timer = null;
                  }
                }, 1000)
              }
            //}
          }).catch(error=>{
            console.log(error.response.data);
            console.log(error.response.status);
            console.log(error.response.headers); 
            console.log('Error', error.message);
            console.log(error.config);
          })

使用场景:

当后端判断验证的手机号已存在的时候会返回400,这时需要跳到error条件中,得到后台400的返回数据如上。

以下是error.response返回值:

这里如果直接输出error,等于error.message

附状态码为200的返回值:

以上这篇前端获取http状态码400的返回值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

应用WEB标准实例:列表页面的制作

应用WEB标准实例:列表页面的制作
收藏 0 赞 0 分享

用CSS构建iframe效果代码

用CSS构建iframe效果代码
收藏 0 赞 0 分享

用CSS给图片打标的方法

用CSS给图片打标的方法
收藏 0 赞 0 分享

用css动态生成闪字的代码

用css动态生成闪字的代码
收藏 0 赞 0 分享

用滑动门技术设计按钮的图文教程

用滑动门技术设计按钮的图文教程
收藏 0 赞 0 分享

用div+css解决出现水平滚动条问题

用div+css解决出现水平滚动条问题
收藏 0 赞 0 分享

ul在Firefox和IE下的不同表现的解决方法

ul在Firefox和IE下的不同表现的解决方法
收藏 0 赞 0 分享

如何实现多风格选择 样式实时切换

如何实现多风格选择 样式实时切换
收藏 0 赞 0 分享

用css实现隐藏文本框

用css实现隐藏文本框
收藏 0 赞 0 分享

css实现行间距效果

css实现行间距效果
收藏 0 赞 0 分享
查看更多