ajax 无刷新 注册整个页面

1.建立ajax.js文件

 //开始

 //声明XMLHttpRequest对象
var xmlHttp;

//检测用户名是否存在
function CheckName(userName,id)
{
    createXMLHTTP();//创建XMLHttpRequest对象
    var url="DisposeEvent.aspx?Name="+encodeURI(userName)+"";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=function(originalRequest){checkUserName(id)}; 
    xmlHttp.send(null);
}

function createXMLHTTP()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();//mozilla浏览器
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
        }
        catch(e)
        {}
        try
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
        }
        catch(e)
        {}
        if(!xmlHttp)
        {
            window.alert("不能创建XMLHttpRequest对象实例!");
            return false;
        }
    }
}

//执行检测用户名回调函数
function checkUserName(id)
{
 
    if(xmlHttp.readyState==4)//判断对象状态
    {
        if(xmlHttp.status==200)//信息成功返回,开始处理信息
        {
              document.getElementById(id).innerText =xmlHttp.responseText;
              
        }
    }
}

function checkpwd(pwd)
{
   var pwdone= document.getElementById("pwd").value;
    if(pwd!=pwdone)//判断对象状态
    {
       document.getElementById("pwdvalue").innerText="两次密码填写不一致";
        document.getElementById("btseave").disabled=true;
    }
    else
    {
     document.getElementById("pwdvalue").innerText="正确";
     document.getElementById("btseave").disabled=false;
    }
}

function checkhandset(handset)
{
    var reg=/^((/(/d{3}/))|(/d{3}/-))?13/d{9}|15[89]/d{8}$/;

    if(!reg.test(handset))
    {
    document.getElementById("handsetvalue").innerText="请输入正确的手机号码格式";
     document.getElementById("btseave").disabled=true;
    }
    else
    {
      document.getElementById("handsetvalue").innerText="正确";
      document.getElementById("btseave").disabled=false;
    }

}

function checkemail(email)
{
    var reg=//w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*/;
    if(!reg.test(email))
    {
      document.getElementById("emailvalue").innerText="请输入正确的emali格式";
      document.getElementById("btseave").disabled=true;
    }
    else
    {
      document.getElementById("emailvalue").innerText="正确";
      document.getElementById("btseave").disabled=false;
    }

}

//结束

2选用的东西,可以不要 ,密码强度判断的脚本;

 

<script language="javascript" type="text/javascript">
//CharMode函数 
//测试某个字符是属于哪一类. 
function CharMode(iN){ 
if (iN>=48 && iN <=57) //数字 
return 1; 
if (iN>=65 && iN <=90) //大写字母 
return 2; 
if (iN>=97 && iN <=122) //小写 
return 4; 
else 
return 8; //特殊字符 

//bitTotal函数 
//计算出当前密码当中一共有多少种模式 
function bitTotal(num){ 
modes=0; 
for (i=0;i<4;i++){ 
if (num & 1) modes++; 
num>>>=1; 

return modes; 

//checkStrong函数 
//返回密码的强度级别 
function checkStrong(sPW){ 
if (sPW.length<=4) 
return 0; //密码太短 
Modes=0; 
for (i=0;i<sPW.length;i++){ 
//测试每一个字符的类别并统计一共有多少种模式. 
Modes|=CharMode(sPW.charCodeAt(i)); 

return bitTotal(Modes); 

//pwStrength函数 
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色 
function pwStrength(pwd){ 
O_color="#eeeeee"; 
L_color="#FF0000"; 
M_color="#FF9900"; 
H_color="#33CC00"; 
if (pwd==null||pwd==&apos;&apos;||pwd.length<6 ||pwd.length>18){ 
Lcolor=Mcolor=Hcolor=O_color; 
document.getElementById("htmdiv").style.display="";
document.getElementById("styl").style.display="none";

else{ 
document.getElementById("styl").style.display="";
document.getElementById("htmdiv").style.display="none";
S_level=checkStrong(pwd); 
switch(S_level) { 
case 0: 
Lcolor=Mcolor=Hcolor=O_color; 
case 1: 
Lcolor=L_color; 
Mcolor=Hcolor=O_color; 
break; 
case 2: 
Lcolor=Mcolor=M_color; 
Hcolor=O_color; 
break; 
default: 
Lcolor=Mcolor=Hcolor=H_color; 

document.getElementById("strength_L").style.background=Lcolor; 
document.getElementById("strength_M").style.background=Mcolor; 
document.getElementById("strength_H").style.background=Hcolor; 
}

return; 

</script>

//结束

3建立DisposeEvent.aspx文件用来接收检测用户名的文件

public partial class DisposeEvent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string regex="^[/u4e00-/u9fa5]{2,6}$";
        string name = Request.QueryString["Name"];
        if (name + "a" == "a")
        {
            Response.Write("不能为空");
            Response.End();
        }
        else if(!publicclass.myreg(name,regex))
        {
            Response.Write("错误:应为 2-6个汉字");
            Response.End();
         }
        else
        {
        
            bool bisLogin = usersManager.isuser(Request.QueryString["Name"].ToString());//换成自己写的查询数据库用户名的方法
            if (bisLogin == false)
            {

                Response.Write("恭喜您该用户名可以用!");
                Response.End();
            }
            else
            {
                Response.Write("对不起,用户名被人用了!");
                Response.End();
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值