Ajax Introduction

Ajax Stand for Asynchronous JavaScript and XML.In Simple word Ajax updates a part of webpage,without reloading the whole page. Ajax is not a single technology, but a group of technologies like HTML,CSS,JavaScript And XML.HTML and CSS is used to mark up and style information.

What You Should Already Know Before Ajax ?

You should have a basic knowladge of the following

  • HTML/XHTML
  • CSS
  • JavaScript/DOM

Applications made in ajax are platform and browser independent.

Example

Step 1

Here is simple Example of Ajax.In this example we load text file data using Ajax.first we create ajaxexample.php

<!DOCTYPE html>
<html>
<head>
<title>Ajax Example</title>
</head>
<body>
<div id="myDiv"><h2>Change text using Ajax</h2></div>
<button type="button" onclick="loadTextFile()">Load Text File</button>
</body>
</html>
Javascript

Add Below javascript code in above created php file.

function loadTextFile()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
 // code for new browser
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

 xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax.txt",true);
xmlhttp.send();
}
Step 2

Here we create ajax.txt file with following text.

Ajax Content