【发布时间】:2014-01-06 01:15:48
【问题描述】:
我不知道是什么问题..
<script type="text/javascript">
$(document).ready(function () {
$("#SendCommentBtn").click(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Pages/PageOne.aspx/SendComment",
data: "{'name':'" + $('#nameTxt').val() + "','comment':'" + $('#commentTxt').val() + "'}",
async: false,
success: function (response) {
$("#nameTxt").val("");
$("#commentTxt").val("");
alert("OK");
},
error: function () {
alert("ERROR");
}
});
});
});
</script>
在我的代码后面
[WebMethod]
public static void SendComment(string name, string comment)
{
using (SqlConnection cnn = new SqlConnection("CONNECTIONSTRING"))
{
cnn.Open();
int CodArt = Convert.ToInt32(HttpContext.Current.Request.QueryString["CodArt"].ToString());
string query = @"INSERT INTO Comment VALUES(@Param1,@Param2,@Param3)";
SqlCommand cmd = new SqlCommand(query, cnn);
cmd.Parameters.AddWithValue("@Param1", CodArt);
cmd.Parameters.AddWithValue("@Param2", comment);
cmd.Parameters.AddWithValue("@Param3", name);
cmd.ExecuteNonQuery();
}
}
我的问题在哪里?我找不到它。我正在使用母版页.. 是否与 Web 表单相同?此代码在母版页中。如果在我的代码后面(SendComment 方法)中放置一个断点,则网络不会停止。就像永远不会到达它一样。
【问题讨论】:
-
您确定该网址吗? stackoverflow.com/questions/348689/…
-
@Dilish 嗨,mm 问题是我使用了母版页,而 SendComment 方法在母版页后面的代码中。我如何从 webforms 调用此方法?
-
您不能将
SendCommentweb 方法移动到页面“PageOne.aspx”本身吗?此外,如果您使用的是母版页,您可以使用 $('#') 其中 controID 是元素的 id,通过 jquery 获取控件。 -
我认为它不会起作用。见这里stackoverflow.com/questions/8577539/…