|
Prev: Strange Safari onClick problem
Next: " in textfields
From: joe on 21 Apr 2008 05:54 I need to read a file into a Javascript variable everytime a Javascipt function is executed. The file is generated by a perl scipt. The filr (a text file) is in the save directory on the server as the javascipt js and perl script. I googled around and find a lot of info regarding some platform and browser. What would be the most compatible way to do this? The program is a simple order form that should display a "units left" value when the javascipt is executed.
From: VK on 21 Apr 2008 06:06 On Apr 21, 1:54 pm, joe <m...(a)invalid.com> wrote: > 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
From: joe on 21 Apr 2008 06:44 VK <schools_ring(a)yahoo.com> wrote: >On Apr 21, 1:54 pm, joe <m...(a)invalid.com> wrote: >> 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?
From: Thomas 'PointedEars' Lahn on 21 Apr 2008 06:56 joe wrote: > VK <schools_ring(a)yahoo.com> wrote: >> On Apr 21, 1:54 pm, joe <m...(a)invalid.com> wrote: >>> 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
From: joe on 21 Apr 2008 08:22 Thomas 'PointedEars' Lahn <PointedEars(a)web.de> wrote: >joe wrote: >> VK <schools_ring(a)yahoo.com> wrote: >>> On Apr 21, 1:54 pm, joe <m...(a)invalid.com> wrote: >>>> 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>
|
Pages: 1 Prev: Strange Safari onClick problem Next: " in textfields |