小弟才学习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;
}
为什么不能实现跳转?哪里写错了?求高手指点
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>