Ajax - 登录
Login.html
<head>
<title>登录</title>
<mce:script src="js/jquery-1.5.2.js" mce_src="js/jquery-1.5.2.js" type="text/javascript"></mce:script>
<mce:script src="js/login.js" mce_src="js/login.js" type="text/javascript"></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="background">
<div id="loginBox">
<span id="title">登录</span>
<div id="LoginMessage">
用户名:
<input id="txtUser" type="text" maxlength="25" class="txtbox" />
<br />
密 码:
<input id="txtPassword" type="password" maxlength="25" class="txtbox" />
<br />
<center>
<div id="loading">
<img src="data:images/loading.gif" mce_src="data:images/loading.gif" alt="login"/></div>
<input id="btnLogin" type="image" src="data:images/login.gif" mce_src="data:images/login.gif"/>
</center>
</div>
</div>
</div>
</div>
</form>
</body>
Login.js:
/*----------------------------------------------------------------
// File Name:login.js
// File Introduce
// check and handler user input
//
// Create Mark
// Create Date: 4/20/2011 11:15:19 PM
// Create by Ben.Jiang
//----------------------------------------------------------------*/ var email_str = /^(?:[a-z/d]+[_/-/+/.]?)*[a-z/d]+@(?:([a-z/d]+/-?)*[a-z/d]+/.)+([a-z]{2,})+$/i; //Email regular expression $(document).ready(function() {
$("#btnLogin").click(function() {
var username = $("#txtUser").val();
var password = $("#txtPassword").val();
if (username == "" || password == "") {//check if the input is legal
alert("用户名和密码不可以为空!");
return false;
}
else if (!email_str.test(username)) {//check if email is legal
alert("邮件地址格式不正确!");
return false;
} else {
$.ajax({
type: "POST",
url: "/Ajax/LoginHandler.ashx", //event handler url
data: "username=" + escape($('#txtUser').val()) + "&password=" + escape($('#txtPassword').val()),//发送ajax请求
beforeSend: function() {
$("#loading").css("display", "block"); //show loading
$("#btnLogin").css("display", "none"); //hide login button
},
success: function(msg) {
$("#loading").hide(); //hide loading
if (msg == "unregistered") {
alert("对不起,该用户未注册!");//user is unregistered
}
if (msg == "frozen") {
alert("对不起,该用户已被冻结!");//user id frozen
}
if (msg == "fail") {
alert("对不起,用户名或密码错误!"); //login failed
}
if (msg == "success") {
parent.document.location.href = "manage.aspx"; //login successfully
}
},
complete: function(data) {
$("#loading").css("display", "none"); //hide loading
$("#btnLogin").css("display", "block"); //show login
}
});
}
return false; //stop client continue submit
}
);
});
LoginHandler.ashx:
/*----------------------------------------------------------------
// File Name:LoginHandler.ashx.cs
// File Introduce
// handler user login
//
// Create Mark
// Create Date: 4/20/2011 12:15:19 PM
// Create by Ben.Jiang
//----------------------------------------------------------------*/ using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
using PLA.BLL;
using PLA.Model;
using Web.App_Code; namespace Web.Ajax
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class LoginHandler : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string username = context.Request["username"];
string password = context.Request["password"]; UserBLL userBLL = new UserBLL();
//check if the user is registered
if (!userBLL.GetUserRegister(username))
{
context.Response.Write("unregistered");
}//check if the user is frozen
else if (!userBLL.CheckUserBanStatusByEmail(username))
{
context.Response.Write("frozen");
}
else
{
LoginBLL loginBLL = new LoginBLL();
//check if the username and password is right
bool flag = loginBLL.ValidateLogin(username, MD5Helper.getMd5Hash(password), null);
if (flag)
{
UserInfo user = userBLL.GetUserInfoByEmail(username);
context.Session["UID"] = user.U_ID;
context.Session["Email"] = user.U_Email;
context.Response.Write("success");
}
else
{
context.Response.Write("fail");
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
Ajax - 登录的更多相关文章
- ajax登录验证-js
1.html代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- python 全栈开发,Day87(ajax登录示例,CSRF跨站请求伪造,Django的中间件,自定义分页)
一.ajax登录示例 新建项目login_ajax 修改urls.py,增加路径 from app01 import views urlpatterns = [ path('admin/', admi ...
- Ajax登录用户名密码
<script src="http://code.jquery.com/jquery-latest.js"></script>#引入jQuery#当点击函数 ...
- Django Ajax登录 防止CSRF
什么是CSRF 维基百科: 跨站请求伪造(英语:Cross-site request forgery),也被称为 one-click attack 或者 session riding,通常缩写为 CS ...
- Django 博客项目01 数据库设计与验证码校验+Ajax登录
数据库设计 from django.db import models from django.contrib.auth.models import AbstractUser class UserInf ...
- 知问前端——Ajax登录
本文,将使用Ajax登录. 一.服务器端代码 is_user.php: <?php require 'config.php'; $query = mysql_query("SELECT ...
- 巨蟒python全栈开发django10:ajax&&登录认证
通过题目进行知识点回顾: 聚合查询 From django.db.models import Avg,Min,Max,F,Q,Count,Sum #查询书籍的平均值 Ret= Models.Book. ...
- 转:ajax的AntiForgery和Authorize 以及ajax登录例子
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/ashcn2001/article/det ...
- 项目:jSon和Ajax登录功能
组件化网页开发 / 步骤二 · 项目:jSon和Ajax登录功能 要熟练编写封装的$.ajax({........})
- 解决shiro自定义filter后,ajax登录无法登录,并且无法显示静态资源的问题
这个问题困扰了我一天,看了下面两个文章,豁然开朗: https://www.cnblogs.com/gj1990/p/8057348.html https://412887952-qq-com.ite ...
随机推荐
- quant_百度百科
quant_百度百科 quant 编辑 quant的工作就是设计并实现金融的数学模型(主要采用计算机编程),包括衍生物定价,风险估价或预测市场行为等.所以quant更多可看为工程师 ...
- (step7.2.4)hdu 2674(N!Again——简单数论)
题目大意:输入一个整数n,输出N! mod 2009 的结果. 解题思路: 1)任意数 n = ( n / 2009) * 2009 + n % 2009 2)40! mod 2009 等于 2 ...
- 解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found
解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found 异常信息: The Struts dispatcher cannot be fou ...
- HDU 4738 双连通模版题
九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711577 题意:给定n个点,m条无向边 下面m行表示u , v ,边权值 求 ...
- C#文件上传和文件下载
#region 文件上传 private void UpLoadFile(string fileName, string fileNamePath, string uriString) { ); if ...
- BZOJ 1578: [Usaco2009 Feb]Stock Market 股票市场( 背包dp )
我们假设每天买完第二天就卖掉( 不卖出也可以看作是卖出后再买入 ), 这样就是变成了一个完全背包问题了, 股票价格为体积, 第二天的股票价格 - 今天股票价格为价值.... 然后就一天一天dp... ...
- cocos2d-x游戏开发系列教程-中国象棋06-游戏规则
前情回顾 上一个博文我们提到象棋运动的函数dealWithChess,但是只是说该函数完成了棋子的选择和移动功能 其实在这个函数里,在移动棋子之前,是要对棋子的移动是否合法进行判断的,我们一起来看看如 ...
- 基于二叉树和数组实现限制长度的最优Huffman编码
具体介绍详见上篇博客:基于二叉树和双向链表实现限制长度的最优Huffman编码 基于数组和基于链表的实现方式在效率上有明显区别: 编码256个符号,符号权重为1...256,限制长度为16,循环编码1 ...
- AdapterView<?> arg0, View arg1, int arg2, long arg3參数含义
arg0:是指父Vjew arg1就是你点击的那个Item的View arg2是position,position是你适配器里面的position arg3是id,通常是第几个项.id是哪个项View ...
- Core 中文文档
ASP.NET Core 中文文档 第二章 指南(1)用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序 原文:Your First ASP. ...