【问题标题】:Loading Jqgrid in asp.net not functioning as expected在 asp.net 中加载 Jqgrid 未按预期运行
【发布时间】:2015-12-09 11:40:48
【问题描述】:

我在加载 jqgrid 时遇到问题。

这是我的脚本

<script type="text/javascript">
    $(document).ready(function() {
       jQuery("#jQGridDemo").jqGrid({
          url: 'Default.aspx/getData?2',
          datatype: "json",
          colNames: ['Dosage', 'Drug', 'Patient', 'Date'],
          colModel: [
          { name: 'Dosage', index: 'Dosage', width: 20},
          { name: 'Drug', index: 'Drug', width: 150, stype: 'text'},
          { name: 'Patient', index: 'Patient', width: 150},
          { name: 'Date', index: 'Date', width: 60}
          ],
          rowNum: 10,
          mtype: 'POST',
          loadonce: true,
          rowList: [10, 20, 30],
          pager: '#jQGridDemoPager',
          viewrecords: true,
          sortorder: 'desc',
          caption: "List Employee Details",
          loadComplete: function (result) {
          debugger;
          var i = 0;
          alert(result);
          },
          loadError: function (xhr) {
          // debugger;
          alert("The Status code:" + xhr.status + " Message:" + xhr.statusText); //Getting reponse 200 ok
          }           
       });    
    });
</script>

//我正在从默认页面调用该函数。这是我的 C# 代码。 //我没有使用 val 但我需要传递参数的示例。

[WebMethod(EnableSession = true)]
public string getData(int val)
{
    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
    table.Columns.Add("Drug", typeof(string));
    table.Columns.Add("Patient", typeof(string));
    table.Columns.Add("Date", typeof(DateTime));

    // Here we add five DataRows.
    table.Rows.Add(25, "Indocin", "David", DateTime.Now);
    table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
    table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
    table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
    table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);

    return JsonParser.getJSONString(table);
}

我收到错误消息。任何机构请帮助我?我第一次使用 jqgrid,看到了很多例子并尝试做同样的事情,但没有在网格中得到结果。

【问题讨论】:

  • 你能包括你得到的错误吗?
  • I am getting error。什么错误?
  • 另加[ScriptMethod(UseHttpGet = true)]
  • 我得到状态码=200
  • 你能不能用Fiddler或者IE/Chrome的开发者工具来做jqGrid和服务器之间通信的HTTP跟踪。您能否将您的问题(点击问题文本下的“编辑”链接)附上确切的服务器响应(至少一行数据)?

标签: jquery asp.net jqgrid


【解决方案1】:

您需要创建您的WebMethod static,因为PageMethods 始终是static

[WebMethod(EnableSession = true)]
public static string getData(int val)
{
 //your code.
}

您还需要在 ajax 调用中将参数作为 data 传递。

data : JSON.stringify({ val : 2}),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 2019-09-07
    • 1970-01-01
    相关资源
    最近更新 更多