C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Display Contents of a File using AJAX


Posted Date: 09 Jul 2008    Resource Type: Code Snippets    Category: AJAX
Author: Kundan Kumar SinhaMember Level: Gold    
Rating: Points: 8



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>







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Display the content of File Using Ajax  .  Display contents of a file using AJAX  .  Display contents of a file  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: AJAX - FilteredTextBoxExtender - How to use it in Projects
Previous Resource: Ajax Textbox with AutoComplete feature
Return to Discussion Resource Index
Post New Resource
Category: AJAX


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use