473,396 Members | 1,683 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,396 software developers and data experts.

Re: Read a file into Javascript variable from the server

VK
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
Jun 27 '08 #1
3 3003
joe
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">
....
function showstatus()
{
var jmystat="";

eval('http://www.server.com/cgi-bin/script.pl');

/* 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 */

</script>
Any way to do above or get the same result?
Jun 27 '08 #2
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
--
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
Jun 27 '08 #3
joe
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>
Jun 27 '08 #4

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

Similar topics

7
by: Christian Schmitt | last post by:
Hi, I want to write a script that (run from a file on the local HD) reads another local html-file into a variable, then make some changes to it, and then output the result in a way that makes it...
2
by: Sundar | last post by:
Hi, I am working on ASP.Net. My requirement is that I want to Upload Multiple Files to the Server. I need to have ONLY ONE FILE UPLOAD CONTROL in my page. I SHOULD NOT SUBMIT THE PAGE FOR EACH...
21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
3
by: brett | last post by:
I need to pass a hard coded value to a JS file: <script language="JavaScript" src="Tracking.js" type="text/javascript"></script> Neither of these methods work: <script language="JavaScript"...
5
by: Prabhat | last post by:
Hi All, Is it possible to read any ASP variable from a javascript file (.js) ? Thanks Prabhat
6
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); ...
15
by: Evil Otto | last post by:
My page loads, and calls an init() function that returns content to a div on the page, as well as setting a $_SESSION variable. The content it returns includes a link that calls the same variable,...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
9
by: Matthew Wells | last post by:
OK, I've narrowed down the problem. This works when in the aspx page <script type="text/javascript" > function btnFirst_Click() { alert("Hello");...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.