php ajax用户注册检测代码
index.php 复制PHP内容到剪贴板 PHP代码:
js:ajax.js 复制PHP内容到剪贴板 var xmlHttp;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveX0bject("Msxml2.XMLHTTP");//IE老版本
}
catch(e)
{}
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例");
return false;
}
}
}
php ajax用户注册检测代码
function startRequest(username)
{
createXMLHttpRequest();//特编
xmlHttp.open("GET","ckuser.php?name="+username,true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
//alert("来自服务器的响应:" + xmlHttp.responseText);
if(xmlHttp.responseText == "true"){
document.getElementById("ckuser").innerHTML = '此用户名以被人注册';
}
else if(xmlHttp.responseText == "false")
{
document.getElementById("ckuser").innerHTML = '检测通过';
}
}
}
}
ckuser.php php ajax用户注册检测代码
PHP代码:
//
//require_once "globals.php";
require_once "config.inc.php";
//require_once 'common/common.php';
$username = $_GET["name"];
$con = @mysql_connect("$dbserver","$dbuser","$dbpass" )or die("无法连接到数据库!");
mysql_query("set names gbk");
mysql_select_db("$dbname",$con)or die("无法选择数据库!");
$query="select id from hj_member where username='".$username."';";
$res=mysql_query($query);
if(mysql_num_rows($res)!=0)
{
echo "true";
}else
{
echo "false";
}
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号