3天前代碼工作正常。但現在不是。 請指出我的錯誤,因爲我是JQuery的新手。登錄頁面使用JQuery
我調試了一下,發現調試器沒有進入ajax的成功方法裏面。甚至沒有去CS文件。 Jquery-的
代碼
<script type="text/javascript">
$(document).ready(function() {
$('#btnSubmit').click(function() {
alert('b');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "admin.aspx/LogIn",
dataType: "json",
data: "{'name':'" + $('#txtfn').val() + "','password':'" +$('#txtln').val() + "'}",
success: function (data) {
alert(data);
var obj = data.d;
alert(obj);
alert(data.d);
if (obj == 'true') {
$('#txtfn').val('');
$('#txtln').val('');
alert("dasdsad");
window.location = "home.aspx";
alert("success");
}
else if (obj == 'false')
{ alert("errorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); }
},
error: function (result) {
alert(data);
alert("aaaaaaafgdgfdfgsfgfhffghgfhgfhfghfghfhfghfhfghgfhgfhgfhgfhfghfghgfhgfhgf");
alert(result);
}
});
});
});
</script>
</head>
<body>
<div id="login">
<div id="triangle"></div>
<h1>Log in</h1>
<form id="f1" runat="server">
<input type="text" id="txtfn" placeholder="name" />
<input type="text" id="txtln" placeholder="Password" />
<input type="submit" id="btnSubmit" value="Log in" />
</form>
</div>
</body>
代碼 -
[WebMethod]
public static string LogIn(string name, string password)
{
string retMessage = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["oltest_conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string Query = "select * from profile where [email protected] and [email protected]";
using (SqlCommand cmd = new SqlCommand(Query, con))
{
cmd.Parameters.AddWithValue("@pname", name);
cmd.Parameters.AddWithValue("@pwd", password);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//retMessage = "home.aspx";
retMessage = "true";
}
else
{
retMessage = "false";
}
}
return retMessage;
}
}
使用Firefox Firegbug控制檯 – 2014-11-06 07:14:10
我已經使用它...仍然無法找出錯誤。我是JQuery新手 – user2096592 2014-11-06 07:15:58
你是否已經捕獲了這個請求?您可以在Firefox或Chrome中使用網絡標籤。你是否運行該請求? – Fabio 2014-11-06 07:34:36