I have a Vue.js form with a submit button. When clicked, a POST axios request is sent and a visual alert is triggered if the call is valid.
All is working fine but for a tiny little detail. The POST request does not get sent until AFTER the user clicks "OK" from the alert popup. This is not the intended behaviour. The request should be sent for as long as it is a valid call, and the popup is merely a visual confirmation.
Do you have any idea as to why the alert triggers the request? Thanks!
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
axios.post(
"https://dummy.com",
{ name: this.ruleForm },
{
headers: {
"Content-type": "application/json"
}
}
);
alert(
"Success!"
);
} else {
alert("Error at submit. Check required fields.");
console.log("Error at submit. Check required fields.");
return false;
}
});
},
Bonus question: do you know a simple way to trigger a redirect after the user confirmed the alert? :D