index.php
Code listing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="ajax.js"></script>
</head>
<body>
<form action="" method="get">
<p> Enter no </p>
<p>
<input name="no" type="text" onkeyup="sq(this.value)" />
</p>
<p><div id="res"></div></p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="ajax.js"></script>
</head>
<body>
<form action="" method="get">
<p> Enter no </p>
<p>
<input name="no" type="text" onkeyup="sq(this.value)" />
</p>
<p><div id="res"></div></p>
</form>
</body>
</html>
result.php
Code listing:
<?php
echo $_REQUEST['no']*$_REQUEST['no'];
?>
echo $_REQUEST['no']*$_REQUEST['no'];
?>
ajax.php
Code listing:
var xmlhttp
function sq(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="result.php";
url=url+"?no="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("res").innerHTML=xmlhttp.responseText;
}
else
{
document.getElementById("res").innerHTML="PROCESSING..<img src='images/3.gif' />";
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function sq(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="result.php";
url=url+"?no="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("res").innerHTML=xmlhttp.responseText;
}
else
{
document.getElementById("res").innerHTML="PROCESSING..<img src='images/3.gif' />";
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
No comments:
Post a Comment