SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,033
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to detect when an attachment loads?

    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?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Ther is no way to detect it so asynchronous is the only option that you have.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,033
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    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."

    The AJAX script would be in a while loop that could not break until it that APC Cache marker is set by the 1st script. When it sees the marker it sends back a response to javascript of "done".

    It would be tricky to code but has a chance of working. Any thoughts anyone?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    The one delivering the attachment would at conclusion right the session id into the APC Cache with a marker of "I'm done."
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,033
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •