ajax.php
=========
<html>
<script>
function hello(str)
{
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest() ;
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("msg").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","1.php?id="+str,true);
xmlhttp.send();
}
</script>
<input type="text" name="name" onBlur="hello(this.value)">
<span id="msg"></span>
</html>
======
1.php
======
<?php
$name=$_GET['id'];
mysql_connect("localhost","root","");
mysql_select_db("test");
$qu=mysql_query("select * from login where user_name='$name'");
$n=mysql_num_rows($qu);
if($n==1)
{
echo "USERNAME IS NOT AVAILABLE";
}
else
{
echo "OK";
}
?>
=========
<html>
<script>
function hello(str)
{
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest() ;
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("msg").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","1.php?id="+str,true);
xmlhttp.send();
}
</script>
<input type="text" name="name" onBlur="hello(this.value)">
<span id="msg"></span>
</html>
======
1.php
======
<?php
$name=$_GET['id'];
mysql_connect("localhost","root","");
mysql_select_db("test");
$qu=mysql_query("select * from login where user_name='$name'");
$n=mysql_num_rows($qu);
if($n==1)
{
echo "USERNAME IS NOT AVAILABLE";
}
else
{
echo "OK";
}
?>
No comments:
Post a Comment