Re: Read a file into Javascript variable from the server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VK

    Re: Read a file into Javascript variable from the server

    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.

  • joe

    #2
    Re: Read a file into Javascript variable from the server

    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">
    ....
    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?

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Read a file into Javascript variable from the server

      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">
      W3C's easy-to-use markup validation service, based on SGML and XML parsers.

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

      Comment

      • joe

        #4
        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">
        >
        >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('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>

        <body>
        <h2>Using the HttpRequest Object</h2>

        <button onclick="loadXM LDoc('test.dat' )">Get XML</button>

        </body>
        </html>


        Comment

        Working...