• Jquery and ashx achieve login of ajax


    front dc:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            //用jquery实现无刷新的登录验证 
            function login() {
                $.ajax({
                    url: 'Login.ashx', //访问路径 
                    data: 'username=' + $("#username").val() + "&password=" + $("#password").val(), //需要验证的参数 
                    type: 'post', //传值的方式 
                    error: function () {//访问失败时调用的函数 
                        alert("链接服务器错误!");
                    },
                    success: function (msg) {//访问成功时调用的函数,这里的msg是Login.ashx返回的值 
                        //alert(msg);
                        $("#a").html(msg);
                    }
                });
            }
        </script>
    </head>
    <body>
        <input type="text" id="username" />
        <input type="text" id="password" />
        <input type="button" value="登录" onclick="login()" />
        <div id="a">
            <!--这里显示返回信息-->
        </div>
    </body>
    </html>

    ashx dc:

    <%@ WebHandler Language="C#" Class="login" %>
    
    using System;
    using System.Web;
    
    public class login : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string username = context.Request.Form["username"];
            string password = context.Request.Form["password"];
            if (username == "admin" && password == "admin")
            {
                context.Response.Write("登录成功!");
            }
            else
            {
                context.Response.Write("登录失败!用户名和密码错误!");
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    }
  • 相关阅读:
    mysql 状态查看
    Float浮点内存存储方式 转
    printf("%d",5.01)和printf("%f",5)的输出结果
    RMBP
    小D课堂【SpringBoot】接口Http协议开发实战
    尚硅谷【SpringBoot】web(源码讲解太多不建议阅读)
    尚硅谷【SpringBoot】入门
    51cto-spring boot(一Spring4快速入门)
    Eclipse使用Maven时出现:Index downloads are disabled, search results may be incomplete.问题解决
    maven(二)
  • 原文地址:https://www.cnblogs.com/homchou/p/2909871.html
Copyright © 2020-2023  润新知