The code sample tries to display the contents of a file using AJAX.
Save the code with given file name in root folder of your local web server and open http://localhost/testAjax.htm, Type the name of the file located in the same folder i.e. root folder of your local web server and you will find the content of file in text area.
File testAjax.htm Starts
<html> <body> <script type="text/javascript"> function ajaxFunction() {
var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer 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; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } var fn; fn=document.myForm.username.value; xmlHttp.open("GET","time.asp?f="+fn,true); xmlHttp.send(null); }
</script> <form name="myForm"> File Name: <input onblur="return ajaxFunction();" name="username" > Text: <TEXTAREA name="time" rows="12" cols="50"> </TEXTAREA> </form></body> </html>
File testAjax.htm Ends
File time.asp Starts
<%@ Language=VBScript %> <% response.expires=-1 FileName = Request.QueryString("f") 'FileName = "aa.txt" Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath(FileName), 1) Response.Write(f.ReadAll) f.Close
Set f=Nothing Set fs=Nothing %>
<b>File time.asp Ends</b>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|