【发布时间】:2017-12-01 15:31:52
【问题描述】:
我正在试用 Vue 2.0 和 axios,但遇到了一个小问题。 当我尝试使用 axios 向我的 post.php 文件发送发布请求时,$_POST 数组始终为空。
发布功能:
doPost: function() {
console.log("post in progress")
axios.post('api/post.php', {
title: 'foo',
body: 'bar',
userId: 1
})
.then(response => {
console.log(response)
console.log(response.data)
this.filter = response.data
})
.catch(e => {
this.errors.push(e)
})
}
post.php
<?php
header('Content-Type: application/x-www-form-urlencoded');
echo json_encode($_POST);
?>
请求已完成,状态为 200,但返回一个空对象“[]”
注意:当我将 post 端点更改为 jsonplaceholder 工具时,它工作正常。
【问题讨论】:
-
前段时间我发过类似的东西,也许对stackoverflow.com/questions/41457181/…有帮助
-
那个 Content-Type 标头完全没有意义......
标签: javascript php axios