Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Ajax AJAX Example

Related Tutorials


 
 

Share on Google+Share on Google+

AJAX Example

Advertisement
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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 1, 2009

Related Tutorials

Discuss: AJAX Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
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?
DMCA.com