我正在尝试在Vue.js应用中使用axios进行POST请求到本地API,但响应返回的数据为空。使用Postman工具对API进行POST请求正常工作。以下是我的代码:
var the_data = {
title: 'This is title',
description: 'this is description'
}
axios.post('/api/snippets/insert', the_data)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
在API端,我使用了一个简单的PHP脚本,并使用以下代码打印整个 $_POST 请求数据。
var_dump($_POST);
但是这返回了一个空数组。
JSON.stringify(the_data)
或者如果这不起作用,可以使用老牌的 jQuery$.param(the_data)
https://api.jquery.com/jquery.param/ - connexoQs
对象,而不是qs
。 - connexo