ajax异步请求

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ajax实例.aspx.cs" Inherits="jQuery.Ajax实例" %>

<!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 runat="server">
    <title></title>
    <link href="../css/ui-lightness/jquery-ui-1.9.1.custom.min.css" rel="stylesheet"
        type="text/css" />
    <script src="../js/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="../js/jquery-ui-1.9.1.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var loginin = function (data) {
            if (data == "ok") {
                alert("登录成功");
            }
            else if (data == "error") {
                alert("登录失败1");
            }
            else {
                alert("登录失败");
            }
        }

        $(function () {//异步方法             
         $("#Butto").click(function () { $("#login").dialog({ resizable: false, height: 340, width:300, modal: true, buttons: { "登录": function () { var username = $("#username").val(); var psd = $("#psd").val(); alert(username + psd); $.post("loginAjax.ashx", { "username": username, "psd": psd }, loginin); $("#login").dialog("close"); }, "取消": function () { $(this).dialog("close"); } } }); }); }); //控件 function okclick() { alert("ok"); } //后台检测是否登录 动态修改 $(function () { $.post("检测是否登录.ashx", {}, function (data) { if (data == "已经登录") { var bo = $("#Butto"); //方法一 bo[0].value = "已经登录"; $("#Butto").val("已经登录"); //方法二 } }); }) </script> </head> <body> <form id="form1" runat="server"> <input type="button" id="Butto" value="登录" /> <div id="login" title="登录页面" style="display:none"> <table> <tr> <td>用户名:</td> <td> <%-- <input type="text" id="username" runat="server" />--%> <asp:TextBox ID="username" ValidationGroup="ss" runat="server"></asp:TextBox> </td><td> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="ss" runat="server" ControlToValidate="username" Text="不能为空" ErrorMessage="不能为空"> </asp:RequiredFieldValidator></td> </tr> <tr> <td>密码:</td> <td><input type="text" id="psd" /></td> </tr> <tr> <td><asp:Button ID="Button1" ValidationGroup="ss" runat="server" Text="Button" OnClientClick="okclick()" /></td> </tr> </table> </div> </form> </body> </html>

  

posted @ 2013-06-04 11:05  张国朋  阅读(212)  评论(0编辑  收藏  举报