Write an Ajax program to print the content of the myfile.dat. This code asks the user to click a button, fetches data from the server using Ajax techniques and displays that data in the same web page as the button without refreshing the page

Fetch.php

<html>
<head>
<script language="javascript">
varreq=false;
if(window.XMLHttpRequest)
{
req=new XMLHttpRequest();
 }
else  if(window.ActiveXObject)
{
req=new ActiveXObject("Microsoft.XMLHttp");
}
functionfetchdata(datasource,divID)
{
if(req)
  {
req.open("GET",datasource);
req.onreadystatechange=function()
                {
if(req.readyState==4 &&req.status==200)
                    {
document.getElementById(divID).innerHTML=req.responseText;
                    }
               }
req.send(null);
      }
  }
</script>
</head>
<body>
<form>
<input type=button value="Fetch Message" onClick="fetchdata('myfile.txt','myDiv')">
</form>
<div id="myDiv">data will be here</div>
</body>
</html>

myfile.txt

Ajax stands for asyncronousjavascript and xml

Comments

Popular posts from this blog

Create an XML file which gives details of books available in “ABC Bookstore” from following categories. 1)      Technical 2)      Cooking 3)      Yoga And elements in each category are in the following format.     …….     …….     ……. Save the file as “Book.xml” Create an application that reads “Book.xml” file into simple XML object. Display attributes and elements. (Hint:- Use simple_xml_load_file() function). 

Write a simple PHP program which implements Ajax for addition of two numbers

Consider the following relational database: Project (P_Group_No, Project_Title) Student (Seat no, Name, Class, P_Group_No) Write a PHP script to accept project title and display list of students those who are working in a particular project.