Thomas 'PointedEars' Lahn <Po*********@web.dewrote:
>joe wrote:
>VK <sc**********@yahoo.comwrote:
>>On Apr 21, 1:54 pm, joe <m...@invalid.comwrote:
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="JavaScript">
http://validator.w3.org/
>...
function showstatus()
{
var jmystat="";
eval('http://www.server.com/cgi-bin/script.pl');
http://jibbering.com/faq/#FAQ4_40
http://jibbering.com/faq/#FAQ4_43
>/* 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('test.dat') does not work but loadXMLDoc('test.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.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
alert("Success:" + xmlhttp.responseText);
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusText);
}
}
}
</script>
</head>
<body>
<h2>Using the HttpRequest Object</h2>
<button onclick="loadXMLDoc('test.dat')">Get XML</button>
</body>
</html>