Cant find proper method or idea how to...

Discussion in 'Javascript' started by Nevio, Sep 21, 2008.

  1. Nevio

    Nevio Guest

    Hi all.

    Got 1 question and it's troubling me totally. I please someone to
    answer me.

    I'm building one project over php/javascript and it's not problem to
    load practically anything but 1 thing is spending my nerves totally.

    Question is:

    Is it possible somehow to retrieve data in real time mode? I just
    don't wan to use setTimeout or setInterval methods. Something like
    data.onUpdate or something like that hehe :)

    Thanks for helpin me out.

    Cheers!
     
    Nevio, Sep 21, 2008
    #1
    1. Advertising

  2. Nevio

    SAM Guest

    Nevio a écrit :
    > Hi all.
    >
    > Got 1 question and it's troubling me totally. I please someone to
    > answer me.
    >
    > I'm building one project over php/javascript and it's not problem to
    > load practically anything but 1 thing is spending my nerves totally.
    >
    > Question is:
    >
    > Is it possible somehow to retrieve data in real time mode? I just
    > don't wan to use setTimeout or setInterval methods. Something like
    > data.onUpdate or something like that hehe :)
    >
    > Thanks for helpin me out.


    and with some context ?

    (when does the datas have to be updated ?
    and where the new datas are ?
    and where to display these last ones ?)

    Ajax ?


    Js :
    ====
    var data = 'hello ';

    html :
    ======
    your name : <input on change="alert(data+this.value);">


    --
    sm
     
    SAM, Sep 21, 2008
    #2
    1. Advertising

  3. Nevio

    Jorge Guest

    On Sep 21, 12:23 pm, Nevio <> wrote:
    >
    > Question is:
    >
    > Is it possible somehow to retrieve data in real time mode? I just
    > don't wan to use setTimeout or setInterval methods. Something like
    > data.onUpdate or something like that hehe :)



    Because a server can't initiate a transfer, one would initially think
    that there's no way, but there is, yes, and a quite good one, in fact:

    You just need to make sure that there's *always* a (one) pending XHR.
    Upon entering (onload) of the page:

    1.- Post the XHR that will receive the 'real time' data.
    2.- This XHR will complete with either a timeout or because some 'real
    time' data has arrived.
    3.- Post inmediatly after completion ('2') another XHR (goto '1').

    As you can see, whenever/if the server has some 'real time' data to
    send to the client, it can do so through the currently open/pending
    XHR.

    The latest firefoxes can have up to six different, concurrent XHRs
    ongoing, most other browsers can have up to 4. I don't know about IE,
    though.
    See http://preview.tinyurl.com/6mm5tm

    --
    Jorge.
     
    Jorge, Sep 21, 2008
    #3
  4. Jorge <> writes:

    > On Sep 21, 12:23 pm, Nevio <> wrote:
    >>
    >> Question is:
    >>
    >> Is it possible somehow to retrieve data in real time mode? I just
    >> don't wan to use setTimeout or setInterval methods. Something like
    >> data.onUpdate or something like that hehe :)

    >
    >
    > Because a server can't initiate a transfer, one would initially think
    > that there's no way, but there is, yes, and a quite good one, in fact:
    >
    > You just need to make sure that there's *always* a (one) pending XHR.
    > Upon entering (onload) of the page:
    >
    > 1.- Post the XHR that will receive the 'real time' data.
    > 2.- This XHR will complete with either a timeout or because some 'real
    > time' data has arrived.
    > 3.- Post inmediatly after completion ('2') another XHR (goto '1').


    Actually, you don't need XHR at all. It's easier to just push a <script>
    tag to a hidden frame. That way, you don't need to repeat requests; you
    just keep appending to a single reply (and you can do that from a
    different server than your "main" page).

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
     
    Joost Diepenmaat, Sep 21, 2008
    #4
  5. Nevio

    Jorge Guest

    On Sep 21, 10:23 pm, Joost Diepenmaat <> wrote:
    >
    > Actually, you don't need XHR at all. It's easier to just push a <script>
    > tag to a hidden frame. That way, you don't need to repeat requests; you
    > just keep appending to a single reply (and you can do that from a
    > different server than your "main" page).
    >


    Sounds good, but I don't get it or I'm missing something: you request
    a script, but it's not until it has been 'completely' received that it
    executes (right?), it holds the wanted data, and it has to re-request
    another script ?

    If so, there are -as well- going to be multiple requests... or not ?

    And what about security matters ? What if somebody manages to inject
    one of his own scripts instead of yours ? Because one thing is getting
    the wrong data and another different one is letting the door open to
    code injection attacks.

    --
    Jorge.
     
    Jorge, Sep 21, 2008
    #5
  6. Nevio

    Nevio Guest

    On Sep 21, 11:03 pm, Jorge <> wrote:
    > On Sep 21, 10:23 pm, Joost Diepenmaat <> wrote:
    >
    >
    >
    > > Actually, you don't need XHR at all. It's easier to just push a <script>
    > > tag to a hidden frame. That way, you don't need to repeat requests; you
    > > just keep appending to a single reply (and you can do that from a
    > > different server than your "main" page).

    >
    > Sounds good, but I don't get it or I'm missing something: you request
    > a script, but it's not until it has been 'completely' received that it
    > executes (right?), it holds the wanted data, and it has to re-request
    > another script ?
    >
    > If so, there are -as well- going to be multiple requests... or not ?
    >
    > And what about security matters ? What if somebody manages to inject
    > one of his own scripts instead of yours ? Because one thing is getting
    > the wrong data and another different one is letting the door open to
    > code injection attacks.
    >
    > --
    > Jorge.


    Oh... thanks guys for this! I will try to do it over pending XHR but
    kinda
    somehow i see flex ( AS ) as currently the best solution. I'm doing
    some huge chat system
    and kinda better is to just start with AS as I think. But for
    notifiers and rest of it
    ill use this pending XHR methods. Thanks Jorge and rest of you who
    wanted to help me out.

    I dun ever ever ever use iframe. If I need it, I use div instead lol.
    That thing is old and full of security holes as I know.

    Cheers
     
    Nevio, Sep 21, 2008
    #6
    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. Jitendra Sanghani
    Replies:
    1
    Views:
    761
    tina.10
    Mar 19, 2012
  2. Replies:
    10
    Views:
    1,274
    Big K
    Feb 2, 2005
  3. Nagaraj
    Replies:
    1
    Views:
    924
    Lionel B
    Mar 1, 2007
  4. Dr Mephesto

    App idea, Any idea on implementation?

    Dr Mephesto, Feb 4, 2008, in forum: Python
    Replies:
    3
    Views:
    751
    Dennis Lee Bieber
    Feb 5, 2008
  5. Replies:
    0
    Views:
    657
Loading...

Share This Page