javascript to read from another URL and display output?

R

Rich

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.
 
V

VK

Rich said:
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 :)
 
J

jshanman

VK said:
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
 
R

Randy Webb

VK said the following on 3/2/2006 11:33 AM:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top