zoukankan      html  css  js  c++  java
  • jquery ajax 学习3

     最近在学习ajax,先把两个最常用的jqeury ajax方法记下来:

     $.get 写一个最容易的登陆的方法:

     前台页面代码如下:

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
    
                $("#tijiao").click(function () {
                         
    var $txtname = $("#txtname").val(); var $txtpassword = $("#txtpassword").val(); $.get("Handler2.ashx", { names: $txtname, pawdes: $txtpassword }, function (date) { if (date == 1) { alert("成功") window.location.href = "Default7.aspx"; } else { alert("失败") } }) }) }) </script> </head> <body> <form id="form1" runat="server"> <div> <input id="txtname" type="text" name="name" value="" /><br /> <input id="txtpassword" type="text" name="names" value="" /><br /> <input id="tijiao" type="button" value="提交" /> </div> </form> </body> </html>

     2,在一个ashx里面写登陆方法,如果用户名和密码都正确,反回1,反之反回0,然后在前台页面去判断。 在这里就不再去BLL层连数据库了,主要是学习Jquery ajax

    public class Handler2 : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string names = context.Request.QueryString["names"];//传过来的用户名
            string pawdes = context.Request.QueryString["pawdes"];//传过来的密码
            int t = 0;
            if (names == "admin" && pawdes == "admin")
            {
                t = 1;
                context.Response.Write(t);
            }
            else
            {
                t = 0;
               context.Response.Write(t);
            }
            
        
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

      再写一个$.post方法登陆

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
    
                $("#tijiao").click(function () {
                    var $txtname = $("#txtname").val();
    
                    var $txtpawd = $("#txtpawd").val();
    
                    $.post("Handler.ashx", { names: $txtname, pawdes: $txtpawd }, function (date) {
                      
                        if (date == 1) {
                            alert("成功")
                            window.location.href = "Default7.aspx";
                        } else {
                            alert("失败")
                        }
    
                    })
    
    
                })
    
    
    
    
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server" action="Handler.ashx" method="post"  >
       <div>
           <input id="txtname" type="text" name="name" value="" /><br />
            <input id="txtpawd" type="text" name="names" value="" /><br />
            <input id="tijiao" type="button" value="提交" />
       </div>
        
       
       
        </form>
    </body>
    </html>
    

      然后也是在ashx里面判断

    public class Handler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            
            string names = context.Request.Form ["names"];
            string pawdes = context.Request.Form["pawdes"];
            int t = 0;
            if (names == "admin" && pawdes == "admin")
            {
                t = 1;
                context.Response.Write(t);
            }
            else
            {
                t = 0;
               context.Response.Write(t);
            }
            
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

      好的,今天先到这里

  • 相关阅读:
    diango-tinymce富文本编译器
    django 1.10以上版本,引入js
    linux中使用vi 打开文件时,能显示行号
    ubuntu 16.04 系统语言汉化
    ubuntu16.04 一些简单软件安装操作
    urllib -- ProxyHandler处理器(代理设置)
    urllib基本使用-Handler和自定义的opener()
    urllib基本使用 urlopen(),Request
    python3
    Ubuntu安装Mysql+Django+MySQLdb
  • 原文地址:https://www.cnblogs.com/xu3593/p/2825206.html
Copyright © 2011-2022 走看看