I am using pjax and wanted to use the beforesend call to display a message to the user if there have been unsaved changes to the form. I am using the following javascript code
$(document).on('pjax:beforeSend', function() {
if (isDirty) {
alreadyHandled = true;
return confirm('You have unsaved changes! Are you sure you want to continue?');
}
return true;
});
and it is returning multiple windows and I am not sure why. Why is it displaying the same window multiple times and what can I do to make sure that it only throws it once?
It turns out that I was binding pjax multiple times to the same events. Just going through the app and being a lot more careful with my jquery selectors has solved the problem.