日期:2014-05-17 浏览次数:20479 次
;
<script type="text/javascript" src="ajax.js"></script>
<form name="myform" action="" method="post" enctype="text/plain">
用户名:
<input type="text" name="user" value="" onblur="funphp100('php100')"/>
<div id="php100"></div>
</form>
var xmlHttp;
function S_xmlhttprequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function funphp100(name) {
var f=document.myform.user.value;
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
function byphp() {
if(xmlHttp.readyState == 1) {
document.getElementById('php100').innerHTML = "<img src='loading.gif'>";
}
if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML = byphp100;
}
}
}
<?php
if(@$_GET[id]){
sleep(1);
$conn=mysql_connect('localhost','root','');
mysql_select_db('test',$conn);
echo $sql="SELECT * FROM `user` where `user`='$_GET[id]'";
$q=mysql_query($sql);
if(is_array(mysql_fetch_row($q))){
echo "<font color=red>用户名已经存在</font>";
}else
{
echo "<font color=green>可以使用</font>";
}
}
?>
show variables like 'char%'