Eric Evans Eric Evans - 1 year ago 165
jQuery Question

How can I redirect after toastr notification

I'm trying to redirect after toastr notification finishes displaying. I currently have ajax request as

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>';

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?

Answer Source

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 hear

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download