/* at this point the script.pl has read a file from the server in to perl
variable called $mystat. I should now to get that into jmystat somehow */
You need to make an HTTP request. You can use e.g. (i)frames or XHR for that.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: Read a file into Javascript variable from the server
Thomas 'PointedEars' Lahn <PointedEars@we b.dewrote:
>joe wrote:
>VK <schools_ring@y ahoo.comwrote:
>>On Apr 21, 1:54 pm, joe <m...@invalid.c omwrote:
>>>I need to read a file into a Javascript variable everytime a Javascipt function
>>>is executed.
>>http://www.jibbering.com/faq/index.html#FAQ4_18
>>
>My code does something like this:
>SCRIPT LANGUAGE="JavaS cript">
>/* at this point the script.pl has read a file from the server in to perl
>variable called $mystat. I should now to get that into jmystat somehow */
>
>You need to make an HTTP request. You can use e.g. (i)frames or XHR for that.
>
>
>PointedEars
Thanks! The HTTP request approach is what I want. I got it to work but with a
some problems. I downloaded some sample from the net and tested it. The problems
I am having is:
- loadXMLDoc('tes t.dat') does not work but loadXMLDoc('tes t.bin') works. They are
the same file the latter having a different name.
- loadXMLDoc('/somedir/test.bin') does not work
- loadXMLDoc('//somedir//test.bin') does not work
(somedir is an existing directory)
I've made full access to the file. Are there some rules as to what names I can
use and where they can reside?
Here's the full source
<html>
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttp Request)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest( );
}
else if (window.ActiveX Object)
{// code for IE6, IE5
xmlhttp=new ActiveXObject(" Microsoft.XMLHT TP");
}
if (xmlhttp!=null)
{
xmlhttp.onready statechange=sta te_Change;
xmlhttp.open("G ET",url,true) ;
xmlhttp.send(nu ll);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyS tate==4)
{// 4 = "loaded"
if (xmlhttp.status ==200)
{// 200 = "OK"
alert("Success: " + xmlhttp.respons eText);
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusT ext);
}
}
}
</script>
</head>
Comment