zoukankan      html  css  js  c++  java
  • 用JQuery简单实现ajax

    创建页面index.htm

    代码如下:

    <!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="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">
    $(function () {
    $("#btnSubmit").bind("click", function () {
    var username = $("#txtUserName").val();
    var userpassword = $("#txtPassword").val();
    if (username == "" || userpassword == "") {
    $("#demo").html("<span style='color:red;'>对不起,用户名和密码不能为空!</span>");
    return;
    }
    $.get("login.aspx", { username: username, userpassword: userpassword },
    function (data) {
    if (data == "true") {
    $("#demo").html("<span style='color:red;'>恭喜您,登陆成功!</span>");
    }
    else {
    $("#demo").html("<span style='color:red;'>对不起,用户名和密码错误!</span>");
    }
    });
    });

    }
    );
    </script>

    </head>
    <body>
    <div id="demo">
    </div>
    <table style="">
    <tr>
    <td>
    用户名:</td>
    <td>
    <input id="txtUserName" type="text" /></td>
    </tr>
    <tr>
    <td>
    密码:</td>
    <td>
    <input id="txtPassword" type="password" /></td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
    <input id="btnSubmit" type="button" value="登陆" /></td>
    </tr>
    </table>
    </body>
    </html>





    经验在于积累----武二郎
  • 相关阅读:
    Python基础
    thinkphp中session跨域问题
    thinkphp实现短信验证注册
    微信公众号支付流程(Node实现)
    支付宝手机网站支付流程(Node实现)
    浏览器打开URL的方式
    Jmeter取样器之Java Request
    获取Tomcat更详细的日志
    使用PowerDesigner转换不同数据库的表结构
    NameValuePair在API22过时问题
  • 原文地址:https://www.cnblogs.com/zhanghai/p/4461252.html
Copyright © 2011-2022 走看看