以前做项目,如果是静态页面中某个地方要用户登陆的情况下才能操作,这个时候,按之前的方式的话,会用AJAX的方式进行用户登陆。
但现在项目做得多了,安全等性能问题也进入了思考中,这种实现方式的安全性能是有问题的。到大网站去看看,看人家是如何做的,我们也要向大网站看齐嘛,所以我也按人家这种思路来做,安全性能要大大提高了,其实方式很简单,只不过以前有没有做而于。如下:
<span class="anniu"><a href="javascript:void(0)" οnclick="Comment.LoginPOP.postData()">
<img height="38" border="0" width="86" src="http://images.cnblogs.com/2010.08_21.gif"></a></span>
<iframe name="Post_Async_Iframe_POP" id="Post_Async_Iframe_POP" style="display: none;">
</iframe>
<form id="Post_Form_POP" target="Post_Async_Iframe_POP" method="post" style="display: none;">
<input type="hidden" name="txt_hid_UserName_POP" value="" id="txt_hid_UserName_POP" />
<input type="hidden" name="txt_hid_UserPwd_POP" id="txt_hid_UserPwd_POP" />
<input type="hidden" name="txt_hid_Type_POP" id="txt_hid_Type_POP" />
</form>
Comment.LoginPOP = {
defPostUrl: "/aspx/LoginPOP.aspx",//要提交的页面
isWrite: false,
SetData: function () {
//进行为空等判断
$("#txt_hid_UserName_POP").val($("#txt_UserName_POP").val());
$("#txt_hid_UserPwd_POP").val($("#txt_UserPwd_POP").val());
return true;
}, postData: function (url) {
var ispost = this.SetData();
if (!ispost)
return false;
var postForm = document.getElementById("Post_Form_POP")
postForm.action = (!!url) ? url : this.defPostUrl;
postForm.target = "Post_Async_Iframe_POP";
postForm.submit();//进行登陆提交
if (this.timer) clearTimeout(this.timer);
var self = this;
this.timer = setTimeout(function () { //设置超时
if (self.timer) self.timer = null;
alert("系统繁忙,请您稍后重试");
}, 15000);
}, UserLoginCallback: function (code, msg) {
$('Post_Async_Iframe_POP').src = 'about:blank';
if (!this.timer) return;
else clearTimeout(this.timer);
switch (code) {
case 0: alert(msg); break;//登陆失败提示
case 1: alert(msg); break;//登陆失败提示
case 2://登陆成功提示
{
alert(msg);
} break;
}
}
};