In my code snippet, I am utilizing the following method to display a notification after making an ajax request:
const Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 3000 });
//ajax call
$.ajax({
.....
success: function(response){
reloadpanel1(response.id); //another ajax call
reloadpanel2(response.id); //another ajax call
Toast.fire({
type: 'success',
title: response.message,
customClass: { popup: 'adjust' }
})
}
})
One issue encountered is that the notification appears before both reloadpanel1
and reloadpanel2
complete their respective requests. Is there a way to prevent the Toastr
from triggering if all ajax calls have not finished yet?
UPDATE:
The use of $(document).ajaxStart()
or .ajaxStop()
is inappropriate since the message in the notification relies on the value found in the json response.message
.