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

 纪志鹏大利集客_776 发布于 2022-11-04 15:54

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

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

4 个回答
  • https://www.npmjs.com/package...
    post请求默认是发送json格式的数据

    2022-11-12 01:51 回答
  • 可能是axios的post参数问题。参考axios POST

    2022-11-12 01:51 回答
  • 尝试在server端分析,把接收到的参数打印出来看看是否一致

    2022-11-12 01:51 回答
  • 估计哪里写法不对

    2022-11-12 01:51 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有