javascript - 为什么ajax post json后,返回200,但是ajax回调函数却进入error?

查看:170
本文介绍了javascript - 为什么ajax post json后,返回200,但是ajax回调函数却进入error?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

这是ajax代码:

$.ajax({
      url: '/api/v1/register',
      data: JSON.stringify({username: $username, email: $email, password: $password}),
      contentType: 'application/json',
      type: 'POST',
      dataType: 'json',
      success: function (msg) {
        console.log(msg)
        console.log('hello!')
      },
      error: function (error_msg) {
        console.log(error_msg)
        console.log('wrong!')
      }
    })

解决方案

因為返回的內容不是json格式,識別不出來,所以去了error。你可以console.log(error_msg)

这篇关于javascript - 为什么ajax post json后,返回200,但是ajax回调函数却进入error?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆