I'm using an uploader applet that's sending the files to a server side script in php. I want to make sure that, if the user closes the page before the files finish uploading, that the files are deleted from the server since they couldn't be dealt with properly.
The issue comes from the fact that I have one site trying to call two server side scripts at the same time.
If I were to close the page without running the uploader applet, the file deletion script is called with
$(window).bind('beforeunload', function(){
$.post("cancel.php");
});
If I run the uploader applet, however, the event won't trigger and the files just sit on the server. Is there a way to stop the upload script to allow for the cancel script to run? If not, is there a way to wait for the upload script to stop before running the cancel script and before closing the window?
EDIT: Ah, the joy of googling the answer to your question only to see that your question on stack overflow is the top hit on google...
EDIT 2: So after rearranging the order of my calls in my beforeunload event, I've successfully been able to call the scripts that I want when I want. I had to make sure I called cancel()
on the applet before attempting to call the other script.