在HTML页面使用AJAX登录的问题 我有一个 index.htlm 的静态页面,因为这个是首页,要求必须是HTML静态页面,我要在这个页面实现用户登录请问怎么做啊?别告诉我用IFrame未登录时显示2个文本框,1个按钮,登录成功后显示用户名 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //显示注册表单var _newuser=function(){_showmsg("设定帐户名:<input type='text' id='user' class='login' value='"+temp+"' maxlength='15' autocomplete='off'> 密码:<input type='password' id='pass' class='login' value='"+temp2+"' maxlength='15' autocomplete='off'> 确认密码:<input type='password' id='pass2' class='login' maxlength='15' autocomplete='off'> Email:<input type='text' id='mail' class='login' value='"+temp3+"' maxlength='100' autocomplete='off'> 性别:<select id='sex' class='select'><option value='0'>保密</option><option value='1'>男</option><option value='2'>女</option></select><br />密码问题:<select id='question'><option selected='selected' value='0'>您父亲的名字</option><option value='1'>您母亲的出生地</option><option value='2'>您母亲的生日</option><option value='3'>你小学的校名</option></select>答案:<input id='answer' maxlength='15' value='"+temp4+"' type='text' /> <input type='checkbox' id='agree' checked>同意<a href='../../notice' target='_blank'>声明</a> <a href='javascript:regmymy()' target='_self'>完成</a> ");$("msg").innerHTML+="<a href='javascript:_showmsg()' target='_self'>取消</a>" ;}//验证注册信息并调用异步注册事件var regmymy=function(){temp=$("user").value.toLowerCase();temp2=$("pass").value.toLowerCase();temp3=$("mail").value;temp4=$("answer").value;if($("agree").checked==false){alert("非常抱歉,不同意Ismymy服务声明不能使用Ismymy服务。");return;}if(temp.length<2){alert("帐户名至少应有2个字符。");$("user").focus();return;}if(temp.length>25){alert("帐户名至最多25个字符。");$("user").focus();return;}if(!temp.match(/^\w+$/)){alert("帐户名只能使用英文字母、数字和下划线。");$("user").focus();return;}if(temp.indexOf("mymy")!=-1){alert("帐户名中不能含有“mymy”。");$("user").focus();return;}if(temp2.length<6 || temp==temp2){alert("为了安全,密码至少应有6个字符。\n且密码不能与帐户名相同。");$("pass").focus();return;} if(temp2!=$("pass2").value.toLowerCase()) {alert("两次输入的密码不一致。");$("pass").focus();return;} if(!$("mail").value.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/)) {alert("Email地址不正确。");$("mail").focus();return;} if(temp4.length<1){alert("密码答案至少应有1个字符。");$("answer").focus();return;} var content="user="+encodeURIComponent(temp)+"&pwd="+encodeURIComponent(temp2)+"&email="+encodeURIComponent(temp3)+"&sex="+encodeURIComponent($("sex").value)+"&question="+encodeURIComponent($("question").value)+"&answer="+escape(temp4)+"&dotype=regmymy"; dosavemymy("***.aspx",content,"regmymy") };function dosavemymy(url,content,type){ //AJAX异步调用 dotype=type; getHttpRequestObject(); if(xmlhttp) { xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-Length",content.length); xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded"); xmlhttp.onreadystatechange=callback; xmlhttp.send(content); } else { alert("Ismymy使用了AJAX技术,而您的浏览器不支持。"); }}//回传函数function callback(){ if(dotype=="regmymy") {//表示注册的回传处理方式 if(xmlhttp.readyState==4) { but.href=href;but.className="";window.status=""; if(xmlhttp.status==200) { var response=xmlhttp.responseText; if(response=="-1") { alert("对不起,您的注册名已经存在,请更换注册名,谢谢!"); $("user").focus(); return; } else if(response>=100) { alert("恭喜您,注册成功!"); window.location.href=_getmypath(); return; } else { alert("对不起注册失败,请重试!"); return; } } else{alert("发生意外错误,请稍后重试。");} } else { but.href="javascript:alert('正在执行,请等待。')"; but.className="执行中...";window.status="执行中...";} }}后台注册代码自己写 都是要做连接跳转的,你可以参考:http://www.fblog.net.cn/readblog.asp?id=147 刚才发错代码了//显示登陆操作var _showlogin=function(){_showmsg("请输入您的帐户名:<input type='text' id='user' value='"+(_getcookie("")==null?"":_getcookie(""))+"' class='login' maxlength='15' autocomplete='off'> 密码:<input type='password' id='pass' maxlength='15' autocomplete='off'> <input type='checkbox' id='autolog'>下次自动登录 <a href='javascript:_login()' target='_self'>确定</a> <a href='javascript:_showmsg()' target='_self'>取消</a> <a href='javascript:_newuser()' target='_self'>没有帐户?马上注册</a>");$("pass").onkeydown=function(event){var ev=window.event || event;var key=window.event ? ev.keyCode : ev.which;if(key==13){_login();}};};//执行登陆操作var _login=function(){temp=$("user").value.toLowerCase();temp2=$("pass").value;if(temp=="" || temp2==""){alert("帐户或密码为空。");return;} var content="user="+escape(temp)+"&pwd="+escape(temp2)+"&ensure="+$("autolog").checked+"&dotype=_login"; dosavemymy("../mymydeal/mymyuser.aspx",content,"_login")}; .net DataTable问题 编码问题求教 高分:请教个缓存问题 怎么获取Content.aspx?id=后面的值呢? confirm问题! 单击按钮后 执行objectdatasource的查询方法 有办法让网页说话吗? 关于ASP。NET 内置登陆带来的一些小问题 急死人了,"未指定的错误",盼好心人帮忙 为什么我用Literal控件时,不能在设计页面上拖动它的位置? 论坛帖子可否在板块间转移? 请教大家一个WEB的GridView的操作问题(VB2005)
var _newuser=function()
{
_showmsg("设定帐户名:<input type='text' id='user' class='login' value='"+temp+"' maxlength='15' autocomplete='off'> 密码:<input type='password' id='pass' class='login' value='"+temp2+"' maxlength='15' autocomplete='off'> 确认密码:<input type='password' id='pass2' class='login' maxlength='15' autocomplete='off'> Email:<input type='text' id='mail' class='login' value='"+temp3+"' maxlength='100' autocomplete='off'> 性别:<select id='sex' class='select'><option value='0'>保密</option><option value='1'>男</option><option value='2'>女</option></select><br />密码问题:<select id='question'><option selected='selected' value='0'>您父亲的名字</option><option value='1'>您母亲的出生地</option><option value='2'>您母亲的生日</option><option value='3'>你小学的校名</option></select>答案:<input id='answer' maxlength='15' value='"+temp4+"' type='text' /> <input type='checkbox' id='agree' checked>同意<a href='../../notice' target='_blank'>声明</a> <a href='javascript:regmymy()' target='_self'>完成</a> ");
$("msg").innerHTML+="<a href='javascript:_showmsg()' target='_self'>取消</a>" ;
}
//验证注册信息并调用异步注册事件
var regmymy=function()
{temp=$("user").value.toLowerCase();
temp2=$("pass").value.toLowerCase();
temp3=$("mail").value;
temp4=$("answer").value;
if($("agree").checked==false)
{alert("非常抱歉,不同意Ismymy服务声明不能使用Ismymy服务。");return;}
if(temp.length<2)
{alert("帐户名至少应有2个字符。");$("user").focus();return;}
if(temp.length>25)
{alert("帐户名至最多25个字符。");$("user").focus();return;}
if(!temp.match(/^\w+$/))
{alert("帐户名只能使用英文字母、数字和下划线。");$("user").focus();return;}
if(temp.indexOf("mymy")!=-1)
{alert("帐户名中不能含有“mymy”。");$("user").focus();return;}
if(temp2.length<6 || temp==temp2)
{alert("为了安全,密码至少应有6个字符。\n且密码不能与帐户名相同。");$("pass").focus();return;}
if(temp2!=$("pass2").value.toLowerCase())
{alert("两次输入的密码不一致。");$("pass").focus();return;}
if(!$("mail").value.match(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/))
{alert("Email地址不正确。");$("mail").focus();return;}
if(temp4.length<1)
{alert("密码答案至少应有1个字符。");$("answer").focus();return;}
var content="user="+encodeURIComponent(temp)+"&pwd="+encodeURIComponent(temp2)+"&email="+encodeURIComponent(temp3)+"&sex="+encodeURIComponent($("sex").value)+"&question="+encodeURIComponent($("question").value)+"&answer="+escape(temp4)+"&dotype=regmymy";
dosavemymy("***.aspx",content,"regmymy")
};function dosavemymy(url,content,type)
{ //AJAX异步调用
dotype=type;
getHttpRequestObject();
if(xmlhttp)
{
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Length",content.length);
xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange=callback;
xmlhttp.send(content);
}
else
{
alert("Ismymy使用了AJAX技术,而您的浏览器不支持。");
}
}
//回传函数
function callback()
{
if(dotype=="regmymy")
{//表示注册的回传处理方式
if(xmlhttp.readyState==4)
{
but.href=href;but.className="";window.status="";
if(xmlhttp.status==200)
{
var response=xmlhttp.responseText;
if(response=="-1")
{
alert("对不起,您的注册名已经存在,请更换注册名,谢谢!");
$("user").focus();
return;
}
else if(response>=100)
{
alert("恭喜您,注册成功!");
window.location.href=_getmypath();
return;
}
else
{
alert("对不起注册失败,请重试!");
return;
}
}
else{alert("发生意外错误,请稍后重试。");}
}
else
{ but.href="javascript:alert('正在执行,请等待。')";
but.className="执行中...";window.status="执行中...";}
}
}后台注册代码自己写
你可以参考:
http://www.fblog.net.cn/readblog.asp?id=147
//显示登陆操作
var _showlogin=function()
{
_showmsg("请输入您的帐户名:<input type='text' id='user' value='"+(_getcookie("")==null?"":_getcookie(""))+"' class='login' maxlength='15' autocomplete='off'> 密码:<input type='password' id='pass' maxlength='15' autocomplete='off'> <input type='checkbox' id='autolog'>下次自动登录 <a href='javascript:_login()' target='_self'>确定</a> <a href='javascript:_showmsg()' target='_self'>取消</a> <a href='javascript:_newuser()' target='_self'>没有帐户?马上注册</a>");
$("pass").onkeydown=function(event){var ev=window.event || event;var key=window.event ? ev.keyCode : ev.which;
if(key==13){_login();}};};//执行登陆操作
var _login=function()
{temp=$("user").value.toLowerCase();
temp2=$("pass").value;
if(temp=="" || temp2=="")
{alert("帐户或密码为空。");return;}
var content="user="+escape(temp)+"&pwd="+escape(temp2)+"&ensure="+$("autolog").checked+"&dotype=_login";
dosavemymy("../mymydeal/mymyuser.aspx",content,"_login")
};