CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: to access a text file on HTTP server from browser using a script

  1. #1
    Join Date
    Jul 2007

    to access a text file on HTTP server from browser using a script

    i'm coding a HTTP server in C which is an embedded web server to be run on the OMAP board. on a default page when this server is accessed i'm giving an option of information about the processes running on the OMAP board which has other DSP applications running on it other than the web server. This information, i'm storing in a text file on the server side. How to write a script to send this text file from the server so, that on the browser the file contents are displayed.
    Last edited by pnayaka; July 9th, 2007 at 01:09 AM. Reason: correction

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002

    Re: to access a text file on HTTP server from browser using a script

    AJAX is not a language, it is merely a manner in passing information between the server and the client using JavaScript and XML. This being said, you can't code in AJAX to do this. You need a server-side language (PHP, ASP.NET, JSP, etc.) to read the textfile and then output the data. JavaScript will then receive this text as the response text. Here is an example with PHP as the server-side language.

    <script type="text/javascript">
    var AJAX = {
      initialize: function(){
        var xmlHTTP;
        try{xmlHTTP = new XMLHttpRequest();}
          try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
            try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
              alert("Your browser does not support AJAX!");
              return false;
        return xmlHTTP;
      get: function(url, func){
        var obj = this.initialize();
        obj.open('GET', url, true);
        obj.onreadystatechange = function(){
    function parseFile(retText){
      document.getElementById('theDiv').innerHTML = retText;
    <input type="button" value="Get File" onclick="AJAX.get('readfile.php', parseFile)">
    <div id="theDiv"></div>
    PHP Code:
    $content = @file_get_contents($file);
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)