Reputation: 269
I am developing an ASP MVC 5 web application.
In one of my page, I am trying to redirect the user to the home page after sending mail and this will be after showing a SweetAlert Dialog.
Indeed, the process must be in this order:
- Click on Button Confirm
- Showing alert dialog which contains Ok button
- Click on Ok in this dialog
- Close the alert dialog
- Redirecting the user to Home page
The problem is that the process in working for me in this following wrong way:
- Click on Button Confirm
- Redirecting the user to Home page
This is my view :
<input type="submit" value="Confirm" style="margin-left:-270px;" onclick="SendEmail()">
<script>
var SendEmail = function () {
jQuery.ajax({
type: "POST",
url: "/Bestellung/SendMailToUser",
success: function (data) {
swal("Good job!", "Your order has been confirmed with success :)", "success");
window.location = "/Home/Index";
}
})
}
</script>
Upvotes: 2
Views: 3582
Reputation: 13146
You want that user clicks the ok button and performing redirection then;
swal({
title: 'Good job!',
text: "Your order has been confirmed with success :)",
type: 'success',
showCloseButton:true
}).then((result) => {
if (result.dismiss === 'close') {
window.location = "/Home/Index";
}
});
Upvotes: 3