Saturday, September 8, 2012

AJAX Change Text


AJAX Change Text 

AJAX is Asynchronous JavaScript and XML.If you have basic knowledge in Java Scripts and XML is enough for this lesson series. AJAX allows web pages to be updated by exchanging small amounts of data with the servers that it is possible to update parts of a web page, without reloading the whole page.
Importance of AJAX learning:-There are some instances like search auto suggestion we can not do without AJAX along with PHP JS or XML.Example of AJAX usage are Google Maps, Gmail, Youtube, and Facebook tabs.
I am not going to teach you all aspect of AJAX but i will try to present you most important usage example of AJAX
First Create following text file



Then create Following AJAX Script and save file in your root as html file and find the result

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  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","text.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>AJAX change this text Click The Button Bellow</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>


No comments:

Post a Comment