我在 .net 项目中使用 Ajax(不是 MVC.net)。我想从 JScript 函数中调用我的 .aspx.cs 函数。
这是我的 JScript 代码:
$("a#showQuickSearch").click(function () {
if ($("#quick_search_controls").is(":hidden")) {
$.ajax({
type: "POST",
url: "Default.aspx/SetInfo",
data: "{showQuickSearch}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
alert(response.d);
}
});
$("#quick_search_controls").slideDown("slow");
$("#search_controls").hide();
$("#search").hide();
} else {
$("#quick_search_controls").hide();
}
});
这是我的 .aspx.cs 函数:
[WebMethod]
public string SetInfo(string strChangeSession)
{
Label1.Text = strChangeSession;
return "This is a test";
}
问题是我的 .aspx.cs 函数没有被调用,也没有更新 label.text。