# Other Programming > AJAX >  to access a text file on HTTP server from browser using a script

## pnayaka

Hi,
     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.

----------


## PeejAvery

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.

*whatever.html*


```
<html>
<body>

<script type="text/javascript">
var AJAX = {
  initialize: function(){
    var xmlHTTP;
    try{xmlHTTP = new XMLHttpRequest();}
    catch(e){
      try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
      catch(e){
        try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
        catch(e){
          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.send(null);
    obj.onreadystatechange = function(){
      if(obj.readyState==4){
        func(obj.responseText);
      }
    }
  }
}

function parseFile(retText){
  document.getElementById('theDiv').innerHTML = retText;
}
</script>

<input type="button" value="Get File" onclick="AJAX.get('readfile.php', parseFile)">
<div id="theDiv"></div>

</body>
</html>
```

*readfile.php*


```

<?php
$file = 'filename.txt';
$content = @file_get_contents($file);
if($content){
  echo $content;
}
?>


```

----------

