function
createxhr(){
if
(window.XMLHttpRequest){
var
xhr =
new
XMLHttpRequest();
}
else
{
var
version = [
"Msxml2.XMLHTTP.6.0"
,
"Msxml2.XMLHTTP.5.0"
,
"Msxml2.XMLHTTP.4.0"
,
"Msxml2.XMLHTTP.3.0"
,
"Msxml2.XMLHTTP"
,
"Microsoft.XMLHTTP"
];
for
(
var
i=0,len=version.length; i<len; i++){
var
xhr =
new
ActiveXObject(version[i]);
if
(xhr){
break
;
}
}
}
return
xhr;
}
function
$(id){
return
document.getElementById(id);
}
window.onload =
function
() {
$(
'username'
).onblur =
function
(){
var
name = $(
'username'
).value;
var
xhr = createxhr();
xhr.onreadystatechange =
function
(){
if
(xhr.readyState == 4 ){
var
res = $(
'res'
);
res.innerHTML = xhr.responseText;
}
}
xhr.open(
'get'
,
'./data.php?username='
+name,
true
);
xhr.send(
null
);
}
}
代码][JavaScript]代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
$link = mysql_connect(
'127.0.0.1'
,
'root'
,
'slops'
);
mysql_select_db(
'test'
);
mysql_query(
'set names utf8'
,$link);
$username = $_GET[
'username'
];
if
(!empty($username)){
$sql =
"select * from user where username ='$username'"
;
$res = mysql_query($sql);
$result = mysql_num_rows($res);
if
($result>0){
echo
"该用户已存在,请从新选择用户名!!!"
.$username;
}
else
{
echo
"恭喜你,可以注册"
.$username;
}
}
else
{
echo
"用户名不能为空"
;
}
mysql_close();
|