.net Ajax提交到一般处理程序

 

js代码

/*验证登陆*/

/*验证登陆*/
$(document).ready(function() {
    $("#Login").click(function() {
        var username = $("#user").val();//获得用户输入账号
        var password = $("#pass").val();//获得用户输入密码
        $.ajax({
            type: "get", //使用get提交
            url: "../ashx/Login.ashx", //提交到Login.ashx 处理 ashx 后缀的为一般处理程序处理ajax提交
            data: { users: username, passs: password }, //也可以用dta来设置url中要传的参数
            dataType: "script",
            success: function(mesg) {    //mesg 这个参数可以自定义获得login页面输出的字符

                if (mesg == "ok")//如果iogin页面输出的是ok就跳转到后台页面
                {
                    alert("登陆成功");
                    window.location.href = "admin_rj.aspx";
                }
                else {
                    alert("密码错误");
                    login.hide(); //显示登录状态条
                    loginBox.show(); //隐藏登陆框
                }
            }
        });
    });
});

Login.ashx 代码

 public void ProcessRequest(HttpContext context)
    {
        BLL.adminBLL abll = new BLL.adminBLL();
        context.Response.ContentType = "text/plain";
        string username = context.Request.QueryString["users"]; //接受用户名
        string password = context.Request.QueryString["passs"];  //接受密码
        if (abll.Login(username, password)) //判断账号密码是否正确
        {
           context.Response.Write("ok");
           context.Response.End();

        }
    }
   ashx一般处理程序处理ajax提交

 

转载地址:http://hi.baidu.com/feihacker/blog/item/e24615f879d7e00ca8d31180.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值