Axios 异步登录捕捉服务器验证错误,浏览器依然报红色叹号

使用axios提交登录表单到auth控制器,如果验证出错laravel会报422错误,axios的catch方法也已经捕捉到了,但是为什么浏览器依然报红色叹号错误:Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)

  <script>

          // ajax登录
          var url = "{{ route('login.validate') }}";

          $('#account_modal .login-register-box .password-login .form-box .button').click(function(){

            $(this).text('正在登录...');

            axios.post(url, {

              email:  $('input[name=email_name]').val(),

              password: $('input[name=password]').val(),

              _token:'{{csrf_token()}}'

            })

            .then(function (response) {

              console.log(response);

            })

            .catch(function (error) {

              if (error.response) {
                // The request was made and the server responded with a status code
                // that falls out of the range of 2xx
                console.log(error.response.data);
                console.log(error.response.status);
                //console.log(error.response.headers);

              }

              else if (error.request) {
                // The request was made but no response was received
                // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
                // http.ClientRequest in node.js
                console.log(error.request);
              }

              else {
                // Something happened in setting up the request that triggered an Error
                console.log('Error', error.message);
              }

              //console.log(error.config);

            });

          });

      </script>

Axios异步登录捕捉服务器验证错误,浏览器依然报红色叹号

Axios 异步登录捕捉服务器验证错误,浏览器依然报红色叹号

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1
卡尔西法

建议查看电脑网络问题,百度422状态码的含义,这个很少见哦!

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!