search

Home  >  Q&A  >  body text

node.js - axios 请求数据,返回数据 data为空怎么办

axios 请求数据,返回数据 data为空

同样的借口用jq的ajax调用就是好的

$.ajax({
            url: '/yzh/inter/login',
            type: 'post',
            data: {'userName': username, 'passWord': password},
            success: function (res) {
                console.log(res);
            }
        });

下边是axios的发送

var config = {
       headers: {
             'Content-Type': 'application/x-www-form-urlencoded'
       },
       responseType: 'json',// default
       method: 'post'
};

axios.post('/yzh/inter/login', {
    userName: this.ruleForm.username,
    passWord: this.ruleForm.password                           
},config)
.then((res) => {
    //if (res) {
      //state.username = res.data.data
      console.log("haha",res)
   // }
})

返回结果中 data为null

请问这个问题怎么解决啊。。

巴扎黑巴扎黑2863 days ago1038

reply all(4)I'll reply

  • 黄舟

    黄舟2017-04-17 16:39:47

    I guess there’s something wrong with the writing

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:39:47

    Try to analyze on the server side and print out the received parameters to see if they are consistent

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 16:39:47

    It may be a problem with the post parameters of axios. Refer to axios POST

    reply
    0
  • 黄舟

    黄舟2017-04-17 16:39:47

    https://www.npmjs.com/package...
    The default post request is to send data in json format

    reply
    0
  • Cancelreply