【发布时间】:2017-12-26 00:57:26
【问题描述】:
我正在尝试将表单数据从 Vue 资源发送到我的 PHP 页面。我可以看到它显示在 PHP 页面上,但是当我将它作为 JSON 发送回来时,我得到一个空响应。为什么它发送一个空响应?
编辑:
看起来问题是提交按钮的值没有在 PHP 中设置。我不确定为什么会这样。尝试使用$_REQUEST 和axios/$.post,但没有区别。
PHP:
if(isset($_POST['submit']){
echo json_encode($_POST);
}
JS:
this.$http.post('addalbum.php', new FormData($('#submitalbum')))
.then(data => console.log(data));
HTML:
<form class="col s12" id="submitalbum" method="post" action="addalbum.php">
<div class="row">
<div class="input-field col s6">
<input name="artist" placeholder="Artist" type="text">
</div>
<div class="input-field col s6">
<input name="title" placeholder="Title" type="text">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input name="genre" placeholder="Genre">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="released" type="number" name="released" placeholder="Year Released">
</div>
<button @click.prevent="addNewAlbum" name="submit" class="waves-effect waves-light btn">Submit</button>
</div>
</form>
【问题讨论】:
-
你在上面的代码中“发回”在哪里?
-
使用 echo 语句。如果它不是 $_POST 数组,它就可以正常工作。
-
PHP 疯了,我走开,抱歉戳我的脑袋……
-
向我们展示您的
#submitalbum表单 -
更新了我的帖子。
标签: php http post vue.js forms