您当前的位置:首页 > 帝国插件

帝国cms插件ajax判断用户名和邮箱是否存在

来源:帝国CMS插件发布者:帝国CMS模板网时间:2010-06-05收藏本页

在注册页面没修改的话就是e/template/member/register.php中添加js代码
<script type="text/javascript">
//by winston ajax会员邮箱判断
var xmlHttp;

function chkUser(str)
{

if (str.length==0)
{
document.getElementById("chkUser").innerHTML="<font color='red'>请输入用户名</font>";
return;
}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}

var url="../../public/chkuser/index.php";
url=url+"?username="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function chkEmail(str)
{

if (str.length==0)
{
document.getElementById("chkEmail").innerHTML="<font color='red'>请输入邮箱</font>";
return;
}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}

var url="../../public/chkemail/index.php";
url=url+"?email="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=EmailStateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function EmailStateChanged()
{
if (xmlHttp.readyState==4)
{
if (xmlHttp.status==200)
{// 200 = "OK"
document.getElementById("chkEmail").innerHTML=xmlHttp.responseText;
}
else
{
alert("出现未知错误:" + xmlHttp.statusText);
}
}
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
if (xmlHttp.status==200)
{// 200 = "OK"
document.getElementById("chkUser").innerHTML=xmlHttp.responseText;
}
else
{
alert("出现未知错误:" + xmlHttp.statusText);
}
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>

用户名input框改为<input name='username' type='text' id='username' maxlength='30' onkeyup="chkUser(this.value)">
*<span id=chkUser></span>

邮箱input改为<input name='email' type='text' id='email' maxlength='50' onkeyup="chkEmail(this.value)">
*<span id=chkEmail></span>