I'm trying to redirect after toastr notification finishes displaying. I currently have ajax request as
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('value')
},
type: $(form).attr('method'),
url: $(form).attr('action'),
data: $(form).serialize(),
dataType: 'json',
success: function (data) {
toastr.success('Hello','Your fun',{timeOut: 2000,preventDuplicates: true, positionClass:'toast-top-center'});
return window.location.href = '/';
},
error: function (data) {
var html = '<div class="alert alert-danger">Email/Password is invalid</div>';
$('#loginMsg').html(html);
}
The problem is it shows the notification but redirects to quickly to actual read the notification. How can I redirect only after toastr notification hides?
toastr
gives the callback options
toastr.options.onShown = function() { console.log('hello'); } toastr.options.onHidden = function() { console.log('goodbye'); } toastr.options.onclick = function() { console.log('clicked'); } toastr.options.onCloseClick = function() { console.log('close button clicked'); }
inside the function you can use redirect URL
it depends on the plugin which your using check here
I hope this helps😊
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('value')
},
type: $(form).attr('method'),
url: $(form).attr('action'),
data: $(form).serialize(),
dataType: 'json',
success: function(data) {
toastr.success('Hello', 'Your fun', {
timeOut: 2000,
preventDuplicates: true,
positionClass: 'toast-top-center',
// Redirect
onHidden: function() {
window.location.href = '/';
}
});
},
error: function(data) {
var html = '<div class="alert alert-danger">Email/Password is invalid</div>';
$('#loginMsg').html(html);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With