【发布时间】:2019-03-05 20:57:55
【问题描述】:
我在执行 POST 请求时遇到了一个奇怪的问题。我在同一页面上有 3 种不同的带有 post 方法的表单,第一个效果很好。
另外两个似乎有问题:当我点击保存按钮时,它会重定向到带有Cannot POST /http://localhost:4000/cards 的错误页面。页面的 url 是 http://localhost:8080/http://localhost:4000/cards 这是我的本地服务器 url + json 服务器 url。
当我刷新页面时,请求已经生效,因为添加了一张新卡。
这是我的简化代码:
<form action="/http://localhost:4000/teamsettings" method="POST">
<input name="title" class="input-source" v-model="teamsetting.name" type="text">
<input name="description" class="input-source" v-model="teamsetting.description" type="text">
<div type="submit" @click="submitTeamG(teamsetting)">Save</div>
</form>
<form action="/http://localhost:4000/cards" method="POST">
<input v-model="title">
<textarea class="input-resume" v-model="description"></textarea>
<button type="submit" @click="subCard">Save</button>
</form>
<form action="/http://localhost:4000/cards" method="POST">
<input v-model="card.title">
<textarea class="input-resume" v-model="card.description"></textarea>
<button type="submit" @click="modifyCard">Modify</button>
</form>
这是我的 axios 帖子请求:
methods: {
submitTeamG(teamsetting) {
axios.put('http://localhost:4000/teamsettings', {
name: teamsetting.name,
description: teamsetting.description
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
window.location="/backoffice";
},
subCard() {
axios.post('http://localhost:4000/cards', {
title: this.title,
description: this.description,
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
window.location="/backoffice";
},
modifyCard(card) {
axios.put('http://localhost:4000/cards', {
title: card.title,
description: card.description,
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
window.location.reload();
}
},
我可以在重定向到错误页面之前在控制台中看到 404 错误,但是在数据库 json 文件中添加了新数据。这是什么问题?
感谢您的宝贵时间:)
【问题讨论】:
标签: javascript json post vue.js axios