javascript to read from another URL and display output?

Discussion in 'Javascript' started by Rich, Mar 2, 2006.

  1. Rich

    Rich Guest

    Hi,

    I'm very, very new to javascript, so please bear with me if this is a
    silly question.

    My problem is this.

    I would like to some javascript connect to a URL on the same webserver
    and read a CGI. The output from this CGI is not plain HTML but rather
    data which needs to be displayed in a moving graph. Coming from a Perl
    background I'd say I'm looking to do something like:

    while (my $data = read_url(http://whatever) {
    print some pretty moving data across the screen;
    }

    Is something like this possible to do in javascript?

    Tks,

    Rich.
    Rich, Mar 2, 2006
    #1
    1. Advertising

  2. Rich

    VK Guest

    Rich wrote:
    > I would like to some javascript connect to a URL on the same webserver
    > and read a CGI. The output from this CGI is not plain HTML but rather
    > data which needs to be displayed in a moving graph. Coming from a Perl
    > background I'd say I'm looking to do something like:
    >
    > while (my $data = read_url(http://whatever) {
    > print some pretty moving data across the screen;
    > }
    >
    > Is something like this possible to do in javascript?


    Not exactly like that, but you can use XMLHttpRequest to grab data from
    the server, see for instance <http://www.ajaxtoolbox.com>

    Unfortunately XMLHttpRequest implements same-domain security, so you
    can connect only to the server you've got the original page from
    (unless loaded from local drive).

    If you indeed from a Perl background then the work around should be
    obvious ;-) The magic word is LWP :)
    VK, Mar 2, 2006
    #2
    1. Advertising

  3. Rich

    jshanman Guest

    VK wrote:

    > Unfortunately XMLHttpRequest implements same-domain security, so you
    > can connect only to the server you've got the original page from
    > (unless loaded from local drive).


    You could also use the appendChild method:

    var jsel = document.createElement('SCRIPT');
    jsel.type = 'text/javascript';
    jsel.src = "page.pl?request="+request;
    document.body.appendChild (jsel);

    Then your perl page can return javsascipt commands (or function call
    with args). You wouldn't want to put this in a loop though, because if
    tehre is delay, your program would never know. Rather, just append
    another script child in the function that is called from the pl page.

    - JS
    http://www.endeavorpub.com
    jshanman, Mar 2, 2006
    #3
  4. Rich

    Randy Webb Guest

    VK said the following on 3/2/2006 11:33 AM:
    > Rich wrote:
    >> I would like to some javascript connect to a URL on the same webserver
    >> and read a CGI. The output from this CGI is not plain HTML but rather
    >> data which needs to be displayed in a moving graph. Coming from a Perl
    >> background I'd say I'm looking to do something like:
    >>
    >> while (my $data = read_url(http://whatever) {
    >> print some pretty moving data across the screen;
    >> }
    >>
    >> Is something like this possible to do in javascript?

    >
    > Not exactly like that, but you can use XMLHttpRequest to grab data from
    > the server, see for instance <http://www.ajaxtoolbox.com>
    >
    > Unfortunately XMLHttpRequest implements same-domain security, so you
    > can connect only to the server you've got the original page from
    > (unless loaded from local drive).


    If the data that is returned from the XMLHTTPRequest Object is in JSON
    (I know that one for sure, it may not be required to be JSON) then you
    can get around the Cross-Domain security issue. There was even a URL
    posted here in the last week or so that went to a site that showed it in
    action.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Mar 2, 2006
    #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. Jon paugh
    Replies:
    1
    Views:
    683
  2. Marek Kurowski
    Replies:
    1
    Views:
    978
    Mark A. Odell
    Aug 18, 2004
  3. Justme
    Replies:
    9
    Views:
    601
    clayne
    Oct 1, 2006
  4. Paul
    Replies:
    1
    Views:
    424
  5. jmr
    Replies:
    2
    Views:
    320
Loading...

Share This Page