Home Ajax AJAX Example
Questions:Ask|Latest



AJAX Example
Posted on: December 1, 2009 By Deepak Kumar
In the following example we will see how to display server IP address dynamically with the help of AJAX, HTML , & PHP.

AJAX Example

     

In the following example we will see how to display server IP address dynamically with the help of AJAX, HTML, & PHP.

SimpleAjax.html

<html>
<body>
<script type="text/javascript" >
function ajaxfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
  document.timeform.time.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","SimpleAjax.php",true);
xmlhttp.send(null);
}
</script>
<form name="timeform" >
Name:<input type="text" name="Name" onkeyup="ajaxfunction()"; />
<br/>
Time:<input type="text" name="time"/>
</form>
</body>
</html>

SimpleAjax.php

<?php
  echo ($SERVER_ADDR);
?>

SimpleAjax.html

<html>
<body>
<script type="text/javascript" >
function ajaxfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
  xmlhttp=new XMLHttpRequest();
}
else
{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
  if(xmlhttp.readyState==4)
  {
  document.timeform.time.value=xmlhttp.responseText;
  }
}
xmlhttp.open("GET","SimpleAjax.php",true);
xmlhttp.send(null);
}
</script>
<form name="timeform" >
Name:<input type="text" name="Name" onkeyup="ajaxfunction()"; />
<br/>
Time:<input type="text" name="time"/>
</form>
</body>
</html>

Note: In this way we can get different dynamic values of server and other like time, date etc.


Recommend the tutorial

Ask Questions?    Discuss: AJAX Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Mr.Mak
April 12, 2011
ajax

its nice to read these materials
amit
November 16, 2011
subject

hii ....
palo
July 5, 2012
ajax

it just dont work
prashanth
October 12, 2012
output of ajax

What is the output of above example?