gpt4 book ai didi

javascript - 如何使用 jQuery 调用特殊函数?

转载 作者:行者123 更新时间:2023-11-30 05:47:42 24 4
gpt4 key购买 nike

我试图通过调用方法在 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;
}

当我提交时显示错误:状态信息对于此页面无效并且可能已损坏。请帮忙,我不明白问题出在哪里。

最佳答案

  1. 你应该创建函数public static
  2. 为函数添加[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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com