Write Ajax program to read a textfile and print the contents of the file when the user clicks on the Print button.
seta1.html
<html>
<head>
<script>
function fun()
{
str=f1.txt.value;
if(str=="" || str==null)
{
alert("Enter file name");
return false;
}else
{
ob=new XMLHttpRequest();
ob.open("GET","seta1.php?abcd="+str,false);
ob.send();
document.getElementById("result").innerHTML=ob.responseText;
return true;
}
}
</script>
</head>
<body>
<form name="f1" method="GET">
Enter the file name
<input type="text" name="txt" value=""/><br>
<input type="button" value="print" onmouseover="return fun()"/>
<div id="result"></div>
</form>
</body>
</html>
seta1.php
<?php
$file1=$_GET['abcd'];
if($fp=fopen($file1,"r"))
{
while(($line=fgets($fp,80))!=false)
{
echo"<br>".$line;
}
}
else
{
echo"File does not exist .";
}
?>
0 Comments
If anyone has Doubts or suggestions please let me know