利用ajax实现多种注册角色的注册登录检测
来源:互联网 发布:数据分析的相关理论 编辑:程序博客网 时间:2024/05/16 15:32
页面A.aspx:
<script type="text/javascript" language="javascript" src="jsFile/createRequest.js"></script>
//这里我将js写在一个js文件中,用的时候直接导入就可以了。js文件内容在下面:
<body>标签内的内容:
<div> 请问要注册以下哪种身份?</div>
<div>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="sa" Text="课程管理员"/>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="sa" Text="普通学员" Checked="True" />
//因为是在探索过程,所以就做了2个选择。具体大家可以自己增加。
</div>
用户名:<input ID="strUserName" type="text" onblur="startRequest(document.getElementById_x('strUserName').value)"/>
<asp:Label ID="Label1" runat="server" Text="*" CssClass="res_lable" ></asp:Label><br />
A.cs //默认;
//---------------------------------我是性感的分割线的开始----------------------------------------
//好了这里是js文件代码:
var xmlhttpReques;
var s;
function startRequest(strUserName){
checkeRadionButton();
if(strUserName==""){
document.getElementById_x("Label1").innerText="不能为空";
return false;
}
document.getElementById_x("Label1").innerText="*";
var filter=/^/s*[A-Za-z0-9]{4,20}/s*$/;
if (!filter.test(strUserName)) {
document.getElementById_x("Label2").innerText="用户名填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9)/n长度不小于4个字符,不超过20个字符,注意不要使用空格。";
document.getElementById_x('strUserName').focus();
document.getElementById_x('strUserName').select();
return false;
}
document.getElementById_x("Label2").innerText="";
createXMLHttpRequest(); //1.生成xmlhttp对象
var strUrl="resEvent.aspx?strUserName="+strUserName+"&strRadioButton="+s;
xmlhttpReques.open("GET",strUrl,true);//3.执行open("GET/POST","url",true);一般后面还有3个参数,具体大家查看相关书籍。
xmlhttpReques.onreadystatechange=checkUserName;//4.当对象发生变化时执行CheckUseName事件,方法在下面。
xmlhttpReques.send(null); //5.正式向服务器发送请求。到这里才是真正的发送,前面4部皆可以理解为对这里的准备过程。
}
function createXMLHttpRequest(){ //生成xmlHttpRequest对象
if(window.XMLHttpRequest){ // code for ie7+,opera,firefox,sarfi,ect!
xmlhttpReques=new XMLHttpRequest();
}
else if(window.ActiveXObject){ //code for ie6,ie5,ect!
try{
xmlhttpReques=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){ }
}
if(!xmlhttpReques){
window.alert('不能创建xmlHttpRequest实例!');
return false;
}
}
function checkUserName(){ //when 'xmlhttp.onreadystatechange'changed use this method
if(xmlhttpReques.readyState==4){
if(xmlhttpReques.status==200){
if(xmlhttpReques.responseText=="canRes"){
document.getElementById_x("Label1").innerText="可以注册!";
}
else if(xmlhttpReques.responseText=="canNotRes"){
document.getElementById_x("Label1").innerText="该用户名已存在!";
}
}
}
}
function checkeRadionButton(){
if(document.getElementById_x("RadioButton1").checked==true){s="RadioButton1";}
if(document.getElementById_x("RadioButton2").checked==true){s="RadioButton2";}
}
//----------------------------性感分割线结束-------------------------------------------
//下面是B.aspx。前台代码为空。
//B.cs. 仅仅在Page_Load()方法内写代码:
protected void Page_Load(object sender, EventArgs e)
{
string strCheckName = Request.QueryString["strUserName"].ToString();
//striUserName为 XXX.aspx?strUserName的strUserName此值!!wtf。。别用错了哦。
string strSql="select * from UserInfo where LoginName='"+strCheckName+"'";
//哥们默认的注册用户是“普通学员”,即RadioButton1的checked默认为True,所以上面的是默认sql语句。
//若然RadionButton的Checked值都为False,则用户忘记选择时,会发生sqlException异常。
if (Request.QueryString["strRadioButton"] == "RadioButton1") strSql = "select * from AdmiInfo where LoginName='" + strCheckName + "'";
//判断哪个RadionButton按钮被选中,选中的改变查询的Sql语句。注:若有多个表,则需要多条判定语句。
//以下为查询部分,不做详细解释。。strPath 是在Web.config 的ConnectionStrings中预先配置好了。
string strPath = ConfigurationManager.ConnectionStrings["conndb"].ToString();
SqlConnection conn = new SqlConnection(strPath);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = strSql;
SqlDataReader sdr = cmd.ExecuteReader();
if (!sdr.HasRows)
{
Response.Write("canRes");
Response.End();
}
else
{
Response.Write("canNotRes");
Response.End();
}
sdr.Close();
conn.Close();
}
//---------------------------------至此结束-------------------------------
ps:还是不骂qyb了,哈哈。NQD啥都没教多少。。感觉自己效率好低。泪了,累了。。。就让哥给辐射射死吧。
- 利用ajax实现多种注册角色的注册登录检测
- django实现注册 登录 ajax
- 用Rails的Ajax实现注册时的用户名检测
- 初学STRUTS---实现注册/登录/动态检测注册信息
- ajax实现在注册时检测用户名是否注册过。
- Ajax实现简单的登录验证与帐号注册
- 利用bmob实现简单的注册和登录
- jQuery+ajax+php实现注册登录功能
- ajax实现用户登录注册和退出
- 数据库登录注册创建角色
- Javaweb 登录注册的实现
- 用ajax检测的用户注册
- 利用AJAX来检测用户名是否已经被注册
- thinkphp 登录 注册常用检测
- 实现登录和注册
- django实现登录注册
- android 注册、登录实现
- android 注册、登录实现
- 学PS基础:Photoshop 技能167个
- 【转载】PS技术盘点,以后不用去影…
- 按钮实现新闻的上移与下移
- SQL Server2005 安装程序无法获取ASPNET账户的系统账户信息
- man的问题:
- 利用ajax实现多种注册角色的注册登录检测
- JFC系列4之获取用户当前工作路径
- Sun Virtualbox虚拟机里面Ubutnu共享Windows空间的教程
- UVA 10991 Region
- Android 图片缩放,图片圆角处理
- 【供批判】所谓的java十宗罪
- 牧人与海
- 燕子与蟒蛇
- 女主人与侍女们