-
-
// JavaScript Document
- var xmlHttp;
- function S_xmlhttprequest()
- {
- xmlHttp=null;
- if (window.XMLHttpRequest)
- {// code for IE7, Firefox, Opera, etc.
- xmlHttp=new XMLHttpRequest();
- }
- else if (window.ActiveXObject)
- {// code for IE6, IE5
- xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
function getName(name)
- {
if(name = document.myform.name.value)
- {
- S_xmlhttprequest();
- xmlHttp.open("get","data.php?name="+name,true);
- xmlHttp.onreadystatechange = byname;
- xmlHttp.send(null);
- }
}
function byname()
- {
- if(xmlHttp.readyState ==1)
- {
- document.getElementById('name').innerHTML = "loading....";
- }
- if(xmlHttp.readyState == 4)
- {
- if(xmlHttp.status == 200)
- {
- var name = xmlHttp.responseText;
- document.getElementById('name').innerHTML = name;
- }
- }
- }
- function getEmail(email)
- {
- var email = document.myform.email.value;
- if(email =="")
- {
- alert("用户名不能为空");
- document.myform.email.focus();
- return false;
- }
- else
- {
- S_xmlhttprequest();
- xmlHttp.open("get","data.php?email="+email,true);
- xmlHttp.onreadystatechange = byemail;
- xmlHttp.send(null);
- }
}
- function byemail()
- {
- if(xmlHttp.readyState ==1)
- {
- document.getElementById('email').innerHTML = "loading....";
- }
- if(xmlHttp.readyState == 4)
- {
- if(xmlHttp.status == 200)
- {
- var email = xmlHttp.responseText;
- document.getElementById('email').innerHTML = email;
- }
- }
- }
-
复制代码
2、register.php文件
3、data.php页面,用于ajax查询数据库。
-
-
- sleep(1);
- $connt = mysql_connect("localhost","root","123456");
- mysql_select_db('test',$connt );
- mysql_query("set names 'gb2312'");
- if($_GET['name'])
- {
- $name = $_GET['name'];
- $sql = "select * from test where name='$name'";
- $restul = mysql_query($sql);
- $array = mysql_fetch_row($restul);
- // print_r($array);
- if(is_array($array))
- {
- echo "该用户名已经存在";
- }
- else
- {
- echo "该用户名可以用";
- }
- }
- if($_GET['email'])
- {
- $name = $_GET['email'];
- $sql = "select * from test where email='$email'";
- $restul = mysql_query($sql);
- $array = mysql_fetch_row($restul);
- // print_r($array);
- if(is_array($array))
- {
- echo "该邮箱已存在";
- }
- else
- {
- echo "该邮箱可以用";
- }
- }
- ?>
复制代码
由此即可实现用户注册时局部刷新的功能了。
|