I have a script that reloads the page to get a PDF generated by PHP. I could have PHP send the file with a content disposition of 'attachment' and the browser will catch the file, open the save dialog, and general happiness follows.
My boss wants the user to be unable to do anything while this is going on. Tired of arguing the point about the benefit of handling transactions asynchronously, is there a way for me to detect in the origin page when this attachment has arrived so that I can shut of any loading indicator I have running?
Any window events fired by this? I mean, when the browser gets the response and sees it is an attachment and not a page does an event get raised in the calling page?
Ther is no way to detect it so asynchronous is the only option that you have.
Ok, well... Hmm.. I wonder if this would work.
The script requesting the file makes a window.location call to get the attachment then immediately makes an ajax call for confirmation.
This will bring into state 2 PHP scripts on the server. The one delivering the attachment would at conclusion right the session id into the APC Cache with a marker of "I'm done."
It would be tricky to code but has a chance of working. Any thoughts anyone?
How do you propose to get it to do that? It is because there is nothing available on the server or within the browser that gets flagged to say that the file has finished downloading that makes it impossible to tell when the file has finished downloading.
True, but most of the lag is PHP / MySQL slogging through the database to prepare the PDF. Once it's done and it starts sending the file receiving it is going to be near instantaneous because server and client are on a closed intranet.
You're point stands for 99% of worldwide use cases, but I think this might work for this corner case.
Course, it would be much nicer that if the browser would fire some sort of event when the page receives an attachment. Then again, I'm still waiting for upload/download progress bars - or expanding AJAX to allow file transfer.