数据结构:
const testdata = [
{
id: 'string',
name: 'string'
}
]
//============================================================
//400
this.$axios({
method: 'post',
url: 'http://localhost:6801/api/v1/Test',
data: JSON.stringify(testdata),
contentType: 'application/json; charset=UTF-8'
}).then(function (res) {
console.log(res)
})
//400
this.$axios({
method: 'post',
url: 'http://localhost:6801/api/v1/Test',
data: testdata,
contentType: 'application/json; charset=UTF-8'
}).then(function (res) {
console.log(res)
})
//==========================================================
// 换成Jquery Ajax
// 成功 200
$.ajax({
type: "Post",
url: "http://localhost:6801/api/v1/Test",
data: JSON.stringify(testdata),
contentType: "application/json; charset=UTF-8",
success: function (data) {
}
});
求告知 Axios 如何解决传递对象数组的问题。在下刚接触前端,还不是很熟悉。之前用过Jquery。
contentType应该放在headers里,ajax是自己单独处理了
headers: {'Content-Type': 'application/json; charset=UTF-8'},
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632