2

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

当我提交它显示Error :The state information is invalid for this page and might be corrupted。请帮忙,我不明白问题出在哪里。

4

1 回答 1

1
  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;
    }
    
于 2013-06-07T08:05:40.087 回答