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
请问这个问题怎么解决啊。。
这是一个非常简单却经常被人忽略的问题,根本原因就是
返回数据不是标准的 JSON
返回数据不是标准的 JSON
返回数据不是标准的 JSON
重要的事情说三遍,三遍,三遍!!!
下面是标准 JSON 格式示例
下面是非标准格式示例:
JSON 格式一定是一个标准的
String
,key
一定是以双引号开头的字符串,最后一个属性末尾不能有逗号。如何判断是否标准 JSON 格式?