首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net Ajax基础操作,该如何解决

2013-04-02 
asp.net Ajax基础操作小弟才学习Ajax技术,因为是自学的。现在遇到问题,想请教大神,前辈。。做了一个测试:asp

asp.net Ajax基础操作
小弟才学习Ajax技术,因为是自学的。现在遇到问题,想请教大神,前辈。。

做了一个测试:
asp代码:
    <script type="text/javascript" src="jQuery/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#loginBtn").click(function () {
                alert($("#userName").val());
                $.ajax({
                    type: "post",
                    url: "TestAbc.ashx",
                    data: { userName: $("#userName").val(), userPwd: $("#userPwd").val() },
                    success: function (responseText) {
                        if (responseText == "1") {
                            window.location.href = "success.aspx";
                        } else if (responseText == "0") {
                            alert("登录失败...");
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="userName" runat="server"></asp:TextBox>
        <asp:TextBox ID="userPwd" runat="server"></asp:TextBox>
        <asp:Button ID="loginBtn" runat="server" Text="登 录"></asp:Button>
    </div>
ashx 代码:
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Login ll = new Login();
            string userName=context.Request.Params["userName"].ToString();
            string userPwd=context.Request.Params["userPwd"].ToString();


            UserLogin ul = ll.login(userName,userPwd);
            if (null != ul)
            {
                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
为什么不能实现跳转?哪里写错了?求高手指点。。。
[解决办法]
很明显,不能用服务器控件,会导致页面回发

修改如下,代码应该没什么问题

<div>
        <input type="text" id="userName"/>
        <input type="password" id="userPwd"/>
        <input type="button" id="loginBtn" value="登录"/>
    </div>

热点排行