Ajax 登录控件(三)
f
function ajaxLogin(lgoinViewId,loginCtrlId,lgUserName,lgUserPwd,lgCmd,loginStatusId,loginStatusName,loginOutId,loginRemberMe){
this.loginViewId=lgoinViewId ;
this.loginControlId=loginCtrlId ;
this.loginUserName=lgUserName ;
this.loginPassword=lgUserPwd ;
this.loginButton=lgCmd ;
this.loginStatusId=loginStatusId ;
this.loginStatusName=loginStatusName ;
this.loginOutButton=loginOutId ;
this.loginRemberMeId=loginRemberMe;
this.timerId=0;
var cTh=this ;
if(typeof ajaxLogin.__RegisteredView =="undefined"){
ajaxLogin.__RegisteredView=new Array ();
}
ajaxLogin.__RegisteredView.push(this);
//防止多次发送 chk.aspx的请求
if (typeof ajaxLogin.__IsChecked=="undefined"){
ajaxLogin.__IsChecked=0;
}
this.init=function(){
var http=false ;
if(typeof ActiveXObject !="undefined"){
try
{
http=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
http=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
http=false ;
}
}
} else if(XMLHttpRequest ){
try
{
http=new XMLHttpRequest();
}
catch(e)
{
http=false ;
}
}
if(http)
{
$Event(cTh.loginButton,"click",cTh.loginClick );
$Event(cTh.loginOutButton ,"click",cTh.loginOutClick );
$Event(cTh.loginUserName ,"keydown",cTh.nameKeyDown);
$Event(cTh.loginPassword ,"keydown",cTh.pwdKeyDown);
}
return http ;
}
this.showIn=function(){
$(cTh.loginControlId).style.display="none";
$(cTh.loginStatusId).style.display="";
}
this.showOut=function(){
$(cTh.loginStatusId).style.display="none";
$(cTh.loginControlId).style.display="";
}
this.clear=function(){
$(cTh.loginUserName ).value="";
$(cTh.loginPassword ).value="";
try
{
$(cTh.loginRemberMeId ).checked=false ;
}
catch(e)
{
}
}
this.loginOut=function(onCompleted,onRunning,onError){
var http=cTh.init();
if(!http)
return ;
http.open("GET","LoginOut.aspx",true);
http.onreadystatechange=function(){
if(http.readyState==4){
if(http.status==200){
onCompleted();
} else {
onError();
}
} else {
onRunning();
}
}
http.send(null);
}
this.loginOutComplected=function(){
var regView =ajaxLogin.__RegisteredView;
for(var i=0;i<regView.length;i++)
{
regView[i].showOut ();
}
//这个是为了防止同一用户在不同的机子上同时登录用的。
if(cTh.timerId!=0){
window.clearInterval(cTh.timerId);
}
}
this.loginOutRunning=function(){
}
this.loginOutErr=function (){
}
//单击事件的处理
this.loginClick=function(evt){
var name=$F(cTh.loginUserName );
var pwd=$F(cTh.loginPassword );
name=name.trim();
if(name ==""){
alert("用户名不能为空");
$(cTh.loginUserName).focus();
if(window.event){
window.event.returnValue=false ;
} else {
evt.preventDefault();
}
return ;
}
pwd=pwd.trim();
if(pwd ==""){
alert("密码不能为空");
$(cTh.loginPassword ).focus();
if(window.event){
window.event.returnValue=false ;
} else {
evt.preventDefault();
}
return ;
}
var rm="0"
try
{
rm=$(cTh.loginRemberMeId ).checked ? "1":"0";
}
catch(e)
{
}
cTh.login(name ,pwd,rm,cTh.onLoginCompleted ,cTh.onHttpStatusError ,cTh.onLoginRunning);
if(window.event){
window.event.returnValue=false ;
} else {
evt.preventDefault();
}
}
this.loginOutClick=function(evt){
cTh.loginOut(cTh.loginOutComplected ,cTh.loginOutRunning ,cTh.loginOutErr);
if(window.event){
window.event.returnValue=false ;
} else {
evt.preventDefault();
}
}
//keydown事件的处理
this.nameKeyDown=function (evt){
var srcObject;
if(window.event){
srcObject =event.srcElement;
if(event.keyCode==13 ){
$(cTh.loginPassword ).focus();
event.returnValue=false ;
}
} else {
srcObject =evt.target;
if(evt.keyCode==13){
$(cTh.loginPassword ).focus();
evt.returnValue=false ;
}
}
}
this.pwdKeyDown=function(evt){
var srcObject;
if(window.event){
srcObject =event.srcElement;
if(event.keyCode==13 ){
$(cTh.loginButton).click();
event.returnValue=false ;
}
} else {
srcObject =evt.target;
if(evt.keyCode==13){
$(cTh.loginButton ).click();
evt.returnValue=false ;
}
}
}
this.login=function(userName,passwrod,remberMe,onCompletedCallback,onErrorCallback,onRunningCallback){
var http= cTh.init();
if(!http)
return
http.open("POST","Login.aspx",true );
http.onreadystatechange=function(){
var state=http.readyState;
if(http.readyState==4){
if(http.status==200){
onCompletedCallback(http.responseText);
} else {
onErrorCallback(http.status);
}
} else {
if(onRunningCallback ){
onRunningCallback(state);
}
}
}
var params="UserName="+escape(userName)+"&Password="+ escape (passwrod )+"&RememberMe="+remberMe;
http.send(params);
}
this.onLoginRunning=function (state){
}
this.onLoginCompleted=function(data){
debugger
var msg=new messageData(data);
var code=msg.msgCode ();
debugger
var desc=msg.msgDesc ();
switch(code )
{
case 0:
var regView=ajaxLogin.__RegisteredView;
for(var i=0;i<regView.length;i++){
regView[i].showIn();
$Text(regView[i].loginStatusName,desc );
regView[i].clear();
}
cTh.timerId=window.setInterval(cTh.notifyServer,2*60*1000);
break ;
case 1:
case 2:
case 3:
case 4:
case 5:
alert(desc);
break;
default :
alert("浏览器脚本错误");
break ;
}
}
this.notifyServer=function(){
var http=cTh.init();
if(!http) return;
http.open("POST","ImOnLine.aspx",false);
http.send(null);
}
this.isOnline=function(onCompletedCallback,onErrorCallback){
var http=cTh.init ();
if(!http )
return false ;
if(ajaxLogin.__IsChecked==1)
return;
ajaxLogin.__IsChecked=1;
http.open("GET","Chk.aspx",true );
http.onreadystatechange=function(){
var state=http.readyState;
if(http.readyState==4){
if(http.status==200){
onCompletedCallback(http.responseText);
} else {
onErrorCallback(http.status);
}
}
}
http.send(null);
}
this.onCheckUserCompleted=function(data){
var msg=new messageData(data );
var code=msg.msgCode ();
var regView=ajaxLogin.__RegisteredView;
switch(code )
{
case 0:
for(var i=0;i<regView.length;i++)
{
regView[i].showIn ();
$Text(regView[i].loginStatusName ,msg.msgDesc ());
}
cTh.timerId=window.setInterval(cTh.notifyServer,2*60*1000);
break;
case 1:
for(var i=0;i<regView.length;i++)
{
regView[i].showOut ();
$Text(regView[i].loginStatusName ,"");
}
break;
default:
break;
}
}
this.onHttpStatusError=function(status){
alert("服务器错误:"+status );
}
}
--------------------
转载于:https://www.cnblogs.com/dhz123/archive/2008/05/19/2194315.html
Ajax 登录控件(三)相关推荐
- 开始使用asp.net ajax的控件工具包AJAX Control Toolkit
我们来为我们的 toolbox 添加一些资源 , 这个要通过下载安装 asp.net ajax 工具包完成.登录 www.asp.net 点击 AJAX 按钮,然后找到 ASP.NET AJAX Co ...
- SilverLight学习笔记--如何在xaml文件中操作用户在后台代码定义的类(2)--示例篇:创建一个登录控件(原创)(转载本文请注明出处)...
本文将示例如何运用前篇所写知识来建立一个用户自定义的登录控件.此控件界面非常简单,主要涉及的知识点是: 如何创建用户控件(包括对此控件的自定义事件和属性的编写,此处我们将创建一个名为LoginBo ...
- 银行登录控件仿制--防钩子,防嗅探
银行登录控件仿制--防全局钩子,防嗅探 类似于支付宝登录控件.工商.招商银行登录控件,这个是一个DLL钩子,用于注入其他进程 另外有一个控件,用来模拟INPUT控件,近期发布! 变量定义 unit h ...
- VS2017中创建使用 XRM 工具常用登录控件的WPF应用程序,适用CRM9.X版本
VS2017中创建使用 XRM 工具常用登录控件的WPF应用程序,适用CRM9.X版本 前提条件 创建WPF项目和修改版本 添加按钮调用登录控件进行调试 总结 微软dynamics官网之前有个CRM ...
- 认识登录控件(Login、CreateUserWizard、LoginStatus和LoginName)
QQ交流群:13033480 一.新建网站Web 二.窗体配置文件中修改 <authentication mode="Forms" /> 三.新建文件夹Manager, ...
- Asp.net Ajax AutoComplete 控件的用法
AutoComplete控件是微软提供的ASP.NET AJAX Control Toolkit 中的一个控件,是用来实现类似百度搜索的自动完成效果. AutoComplete控件的用法很简单,只要在 ...
- .net2005登录控件
简介: 1.ChangePassword:提供了一个可供用户更改其网站密码的用户界面 2.CreateUserWizard:提供用于创建新网站用户帐户的用户界面 3.Login:提供用于登录到网站的用 ...
- Ajax之三 Ajax服务器端控件
视频课:https://edu.csdn.net/course/detail/27107 [学习目标] 理解并掌握ScriptManager控件的使用 了解ScriptManager控件的使用 理解并 ...
- Ajax Toolkit 控件学习系列(13) ——FilteredTextBoxExtender 控制输入
这个控件的作用是对TextBox所要输入的内容进行过滤控制.按照自己需要过滤,可以自定义,再或者使用定义好的方式. 看效果. 效果不是很突出,说明下,就是只能输入大写字母和数字.因为加了限制,但是具体 ...
- 用友登录控件Vbs脚本
' 郁闷啊.用C# 用 U8Login调 控件 始终Ui线程刷新不足. 总是 象没装显卡的电脑 总是不能刷新界面.' 没想到 Vbs宿主脚本调用 都没有什么问题.调用参照控件也是一样..郁闷啊 ' c ...
最新文章
- Apache Maven 安装与配置-修改源
- 米家扫拖一体机器人重置键_全面升级——米家扫拖机器人1T体验
- vi 搜索命令_vi或vim如何查询关键字
- 【渝粤题库】陕西师范大学200651线性代数 作业(高起专、高起本)
- Android四大组件---BroadcastReceiver
- ESP32 TIMER
- 关于 xib 的使用
- I - 数塔(动态规划)数塔问题
- CSDN:数学公式编辑器
- WiFi 中继/桥接功能 — 基于OpenWRT路由器
- python 金融风控模型_Python金融大数据风控建模实战 基于机器学习
- 基于荔枝派Lichee Nano(全志f1c100s)的u-boot移植(一)
- 局域网、城域网、广域网、国际互联网(internet)
- 电力-平衡式101规约报文解析
- android 蓝牙打印乱码,蓝牙打印机打印中文乱码
- Python中match语句的用法
- Vue 中 provide 和 reject 的使用详解和源码解析
- 如何利用无线远传模块实现工业无线控制系统?
- 143个相见恨晚的排行榜网站,总有一个用得着!
- 商品的价格术语(外贸知识三)