473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

javascript to read from another URL and display output?

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.

Mar 2 '06 #1
3 3885
VK

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 :-)

Mar 2 '06 #2
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

Mar 2 '06 #3
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/
Mar 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Geoff | last post by:
Here's the situation. I have a static html page which we want to update to include some dynamic content. I want a counter that keeps track of the number of times anyone presses the "add" button,...
13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
10
by: Simon | last post by:
Hi, Sorry for the cross posting, but I think it applies to both languages. As we all know, JavaScript is client side and php is server side, (the php code is 'allowed' to do stuff on the...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
1
by: vocalise | last post by:
The title probably isn't very clear, but I haven't been able to find this problem (or I must be having problems figuring out which search strings to use) so I apologize if this has been addressed...
3
by: Steve | last post by:
Hi; I'm working on a demo of using a timer on a web site that is made visible by making a div visible. My "PopIn Box" div is empty on the page. Before making it visible I used javascript to...
14
by: MartinRinehart | last post by:
I can load a dialog by loading an HTML page or by constructing the dialog with JavaScript. What should I be thinking about when I look at this choice?
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.