Trying To Poll Server Via Hidden IFrame

Discussion in 'Javascript' started by pbd22, Mar 14, 2007.

  1. pbd22

    pbd22 Guest

    Hi.

    I am trying to poll a long-running process via a hidden IFrame.
    I am noticing that the online errata gives advice for handling a
    server response:

    window.parent.handleServerResponse();

    The problem I am having with this is that the above function
    gets called ***after*** the long-running response is completed.
    How do I poll the long-running process ****as**** it is being
    executed? Say, every 5 seconds or so?

    I thank you for your help.
    Peter
     
    pbd22, Mar 14, 2007
    #1
    1. Advertising

  2. pbd22

    pbd22 Guest

    On Mar 14, 10:12 am, Randy Webb <> wrote:
    > pbd22 said the following on 3/14/2007 12:48 PM:
    >
    > > Hi.

    >
    > > I am trying to poll a long-running process via a hidden IFrame.
    > > I am noticing that the online errata gives advice for handling a
    > > server response:

    >
    > What "online errata"?
    >
    > > window.parent.handleServerResponse();

    >
    > > The problem I am having with this is that the above function
    > > gets called ***after*** the long-running response is completed.
    > > How do I poll the long-running process ****as**** it is being
    > > executed? Say, every 5 seconds or so?

    >
    > You have the long-running process update a file on the server. Then you
    > check the file for the status. It could be as trivial as setting a
    > variable to false and when it finishes changes that variable to true.
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


    Hi Randy,

    Thanks for your reply.
    Well, that particular function comes from the below link:

    http://www.bazon.net/mishoo/rpc.epl

    But, the "online errata" that I have been following most closely has
    been the bit about RPCs by the engineers at Apple:

    http://developer.apple.com/internet/webcontent/iframe.html

    In both cases, I have found that when my long-running process
    (in this case a video upload via hidden iframe) has completed,
    the client-side function gets called.

    I want to poll the long-running process **as it is happening**. The
    polling routine will query information provided by the server page
    (bytes uploaded, percent, total bytes, time, etc) and return that
    information to the client in intervals of a few seconds for an in-
    process client-side progress display.

    I am glad to hear this isn't too complicated. I am wondering if you
    wouldn't mind providing the steps, code, links, or whatever you think
    could help me get my mind wrapped around what I am trying to do. I'd
    apprecaite that.

    Thanks again.
    Peter
     
    pbd22, Mar 14, 2007
    #2
    1. Advertising

  3. pbd22

    shimmyshack Guest

    On 14 Mar, 17:38, "pbd22" <> wrote:
    > On Mar 14, 10:12 am, Randy Webb <> wrote:
    >
    >
    >
    > > pbd22 said the following on 3/14/2007 12:48 PM:

    >
    > > > Hi.

    >
    > > > I am trying to poll a long-running process via a hidden IFrame.
    > > > I am noticing that the online errata gives advice for handling a
    > > > server response:

    >
    > > What "online errata"?

    >
    > > > window.parent.handleServerResponse();

    >
    > > > The problem I am having with this is that the above function
    > > > gets called ***after*** the long-running response is completed.
    > > > How do I poll the long-running process ****as**** it is being
    > > > executed? Say, every 5 seconds or so?

    >
    > > You have the long-running process update a file on the server. Then you
    > > check the file for the status. It could be as trivial as setting a
    > > variable to false and when it finishes changes that variable to true.

    >
    > > --
    > > Randy
    > > Chance Favors The Prepared Mind
    > > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

    >
    > Hi Randy,
    >
    > Thanks for your reply.
    > Well, that particular function comes from the below link:
    >
    > http://www.bazon.net/mishoo/rpc.epl
    >
    > But, the "online errata" that I have been following most closely has
    > been the bit about RPCs by the engineers at Apple:
    >
    > http://developer.apple.com/internet/webcontent/iframe.html
    >
    > In both cases, I have found that when my long-running process
    > (in this case a video upload via hidden iframe) has completed,
    > the client-side function gets called.
    >
    > I want to poll the long-running process **as it is happening**. The
    > polling routine will query information provided by the server page
    > (bytes uploaded, percent, total bytes, time, etc) and return that
    > information to the client in intervals of a few seconds for an in-
    > process client-side progress display.
    >
    > I am glad to hear this isn't too complicated. I am wondering if you
    > wouldn't mind providing the steps, code, links, or whatever you think
    > could help me get my mind wrapped around what I am trying to do. I'd
    > apprecaite that.
    >
    > Thanks again.
    > Peter


    why not have a second iframe, hidden like the first (OR use XHR), but
    this one is used to receive data.
    you /can/use the other one provided it is able to keep flushing small
    bits of javascript back. In the past I have found the simpler way was
    to keep querying a 2nd iframe (or scriptin using XHR) whose source is
    "are_we_there_yet_papa_smurf.php?filename=uploadedfilename"
    or where a session is set and the filename is not needed to be sent.

    that way the are_we_there_yet_pap_smurf.php script can stat the
    uploading file, perform the calculations and send back the data inside
    script tags, (or when using XHR, pre JSON data for security)
    a receiving script in the parent then uses this javascript data to
    update the DOM with the details.
    you call are_we_there_yet_pap_smurf.php using an interval (or
    setTimout) based on a variable sent back, doagain = 1, on upload
    succeeded the variable is changed to doagain = 0; and the thing
    updates once with the final data, and stops.

    Does that all make sense?
     
    shimmyshack, Mar 14, 2007
    #3
  4. pbd22

    pbd22 Guest

    On Mar 14, 5:56 pm, Randy Webb <> wrote:
    > pbd22 said the following on 3/14/2007 1:38 PM:
    >
    >
    >
    > > On Mar 14, 10:12 am, Randy Webb <> wrote:
    > >> pbd22 said the following on 3/14/2007 12:48 PM:

    >
    > >>> Hi.
    > >>> I am trying to poll a long-running process via a hidden IFrame.
    > >>> I am noticing that the online errata gives advice for handling a
    > >>> server response:
    > >> What "online errata"?

    >
    > >>> window.parent.handleServerResponse();
    > >>> The problem I am having with this is that the above function
    > >>> gets called ***after*** the long-running response is completed.
    > >>> How do I poll the long-running process ****as**** it is being
    > >>> executed? Say, every 5 seconds or so?
    > >> You have the long-running process update a file on the server. Then you
    > >> check the file for the status. It could be as trivial as setting a
    > >> variable to false and when it finishes changes that variable to true.

    >
    > >> --
    > >> Randy
    > >> Chance Favors The Prepared Mind
    > >> comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > >> Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

    >
    > > Hi Randy,

    >
    > > Thanks for your reply.
    > > Well, that particular function comes from the below link:

    >
    > >http://www.bazon.net/mishoo/rpc.epl

    >
    > > But, the "online errata" that I have been following most closely has
    > > been the bit about RPCs by the engineers at Apple:

    >
    > >http://developer.apple.com/internet/webcontent/iframe.html

    >
    > > In both cases, I have found that when my long-running process
    > > (in this case a video upload via hidden iframe) has completed,
    > > the client-side function gets called.

    >
    > > I want to poll the long-running process **as it is happening**. The
    > > polling routine will query information provided by the server page
    > > (bytes uploaded, percent, total bytes, time, etc) and return that
    > > information to the client in intervals of a few seconds for an in-
    > > process client-side progress display.

    >
    > > I am glad to hear this isn't too complicated. I am wondering if you
    > > wouldn't mind providing the steps, code, links, or whatever you think
    > > could help me get my mind wrapped around what I am trying to do. I'd
    > > apprecaite that.

    >
    > The IFrame that is hosting the call to the "long running process" can
    > also poll the server to see if the long running process is finished or
    > not. One possible way of doing that is to modify the long running
    > process to write a file - on the server - that estimates how far along
    > it is. Your second poll checks that file and sees where it is at. Then
    > it can update the main page.
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


    Thanks Both.
    This has been an extremely helpful thread.
    Randy, I like your idea of using the same iframe for polling as
    upload, but only have one question about writing to a second file for
    data updates. I have designed a custom event handler that gets called
    every time bytes get uploaded to the FTP server. This event handler
    would be updating the second page with new upload information. To me,
    this means that there would be a ton of read/writes happening on the
    server as the data page gets updated. Wouldn't this method be sort of
    costly to the server?
     
    pbd22, Mar 15, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. birdsong

    select.poll.poll() never blocks

    birdsong, Feb 12, 2009, in forum: Python
    Replies:
    2
    Views:
    472
    birdsong
    Feb 12, 2009
  2. Jean-Paul Calderone

    Re: select.poll.poll() never blocks

    Jean-Paul Calderone, Feb 12, 2009, in forum: Python
    Replies:
    3
    Views:
    460
    birdsong
    Feb 12, 2009
  3. Daedalous
    Replies:
    3
    Views:
    827
    Daedalous
    Jan 16, 2004
  4. Replies:
    0
    Views:
    940
  5. jon
    Replies:
    10
    Views:
    281
    Evertjan.
    Dec 6, 2006
Loading...

Share This Page