我试图通过调用方法在 jQuery 中通过 post 方法获取字符串。 这是我的代码:
$("#btn_Submit").submit(function () {
$.ajax({
type: "POST",
url: "frm_GetTable.aspx/GetComment",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Replace the div's content with the page method's return.
$("#Comment").empty().html(data);
}
});
这是我的职责:
protected String GetComment ()
{
String Comment="";
Comment=(" <table>");
foreach (DataRow dr in dt_Comment)
{
Comment +=("<tr ><td> </td><td rowspan='2'> " + dr["Com"].ToString() + " </td></tr>");
Comment += ("<tr><td >" + dr["Date"].ToString() + "</td></tr>");
}
Comment += ("</table>");
return Comment;
}
当我提交时显示错误:状态信息对于此页面无效并且可能已损坏
。
请帮忙,我不明白问题出在哪里。
最佳答案
- 你应该创建函数
public static
为函数添加
[WebMethod]
属性[WebMethod] public static string GetComment() { String Comment = ""; Comment = (" <table>"); foreach (DataRow dr in dt_Comment) { Comment += ("<tr ><td> </td><td rowspan='2'> " + dr["Com"].ToString() + " </td></tr>"); Comment += ("<tr><td >" + dr["Date"].ToString() + "</td></tr>"); } Comment += ("</table>"); return Comment; }
关于javascript - 如何使用 jQuery 调用特殊函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16979093/