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


  本文标签:http,状态码

如下所示:

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的返回值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家 。

您可能感兴趣的文章:

  • Nginx下301重定向域名的方法小结
  • Apache Rewrite实现URL的301跳转和域名跳转
  • 比较详细的win2003 IIS6.0 301重定向带参数的问题解决方法
  • IIS7.5下301重定向的设置方法(及伪静态后301重定向出错案例)
  • php 301转向实现代码
  • iis下设置301 Redirect 永久重定向的方法
  • php 实现301重定向跳转实例代码
  • HTTP 错误 500.19- Internal Server Error 错误解决方法
  • nginx提示:500 Internal Server Error错误的解决方法
  • HTTP错误500.19解决方法(定义了重复的节点)
  • http状态码汇总及问题经验总结
  • javascript学习笔记(七)Ajax和Http状态码
  • ASP.NET设置404页面返回302HTTP状态码的解决方法
  • http状态码一览表
  • PHP获取访问页面HTTP状态码的实现代码
  • 详解HTTP状态码
  • 10个常见的HTTP状态码详解