How make redirect to another page with post data like php form?
<button @click="sendData(foo)">Submit</button>
------------------------------
sendData(foo){
//redirect to another page with post data $_POST['foo']
....
}
How make redirect to another page with post data like php form?
<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);
});
}
Notice that this won't redirect, since you're using AJAX, but it will submit the form using post.
To redirect, you will have to tell me how your setup is done, if you have something like vue router you should use something similar to:
router.go('/some_url.php')
Otherwise you may need:
location.href = '/some_url.php';
This two would go inside your success function.
This comes in very handy in situations where you need to redirect to an external site e.g payment checkout etc
axios.post(this.baseUrl, this.data)
.then(function (response) {
window.location = response.data.redirect; // full URI to redirect to
})
.catch(function (error) {
});