如何在 Vue 中使用 post 数据重定向到另一个页面?
How redirect to another page with post data in Vue?
如何使用 post 数据(如 php 表单)重定向到另一个页面?
<button @click="sendData(foo)">Submit</button>
------------------------------
sendData(foo){
//redirect to another page with post data $_POST['foo']
....
}
sendData(foo){
axios.post('/a_url.php', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
//REDIRECT TERE
})
.catch(function (error) {
console.log(error);
});
}
请注意,这不会重定向,因为您使用的是 AJAX,但它会使用 post 提交表单。
要重定向,你必须告诉我你的设置是如何完成的,如果你有类似 vue router 的东西,你应该使用类似于:
router.go('/some_url.php')
否则您可能需要:
location.href = '/some_url.php';
这两个将进入您的成功功能。
这在您需要重定向到外部站点的情况下非常方便,例如付款结帐等
axios.post(this.baseUrl, this.data)
.then(function (response) {
window.location = response.data.redirect; // full URI to redirect to
})
.catch(function (error) {
});
如何使用 post 数据(如 php 表单)重定向到另一个页面?
<button @click="sendData(foo)">Submit</button>
------------------------------
sendData(foo){
//redirect to another page with post data $_POST['foo']
....
}
sendData(foo){
axios.post('/a_url.php', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
//REDIRECT TERE
})
.catch(function (error) {
console.log(error);
});
}
请注意,这不会重定向,因为您使用的是 AJAX,但它会使用 post 提交表单。
要重定向,你必须告诉我你的设置是如何完成的,如果你有类似 vue router 的东西,你应该使用类似于:
router.go('/some_url.php')
否则您可能需要:
location.href = '/some_url.php';
这两个将进入您的成功功能。
这在您需要重定向到外部站点的情况下非常方便,例如付款结帐等
axios.post(this.baseUrl, this.data)
.then(function (response) {
window.location = response.data.redirect; // full URI to redirect to
})
.catch(function (error) {
});