2

我在 jquery modile 的代码中使用 jTable,我从查询字符串中获取参数并绑定到 jtable,但我收到错误:与服务器通信时发生错误。

这是我的代码

  <script type="text/javascript">
            $(document).delegate('.ui-page', 'pageshow', function () {
                $('#ResultContainer').jtable({
                    title: 'Search List',
                    paging: true, //Enables paging
                    pageSize: 10, //Actually this is not needed since default value is 10.
                    sorting: true, //Enables sorting
                    actions: {
                        listAction: "SearchResult.aspx/GetSearch"

                    },
                    fields: {
                        Ref: {
                            title: "Ref",
                            width: '30%'
                        },
                        Trademark: {
                            title: 'Trademark',
                            width: '30%'
                        }
                    }
                });
                $('#ResultContainer').jtable('load', {
                    org: '<%= Request["org"] %> ',
                    catchword: ('<%= Request["tm"] %> ')
                });
            });

我的网络方法是

[WebMethod(EnableSession = true)]
public static object GetSearch(string org, string catchword, int jtStartIndex, int jtPageSize, string jtSorting)
{
    List<Coverage> tm = new List<Coverage>();
    try
    {
        //Get data from database
        using (ORepository repository = new ORepository())
        {
            tm = repository.getCoveragebyTM(catchword, org,0,10,"catchword");
            int cnt = tm.Count;
            return new { Result = "OK", Records = tm, TotalRecordCount = cnt };
        }
    }
    catch (SqlException ex)
    {
        return new { Result = "ERROR", Message = ex.Message };
    }
}

任何人都可以请帮助我。如何在页面加载时调用 $('#ResultContainer').jtable('load', {..

编辑:

我在 System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary 2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary2 参数)\r\n 在 System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext 上下文,WebServiceMethodData methodData,IDictionary`2 rawParams)\r\n 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

4

3 回答 3

3

您没有为 org 和流行语参数传递任何值。您可以使用 listAction: "SearchResult.aspx/GetSearch?org=asd&catchword=asd"

此外,您可以使用 firebug 或 chrome dev 工具检查网络包以查看错误详细信息。

于 2013-03-21T20:09:52.990 回答
1

JTable执行结果,有两种状态标识,ok,others。当状态是!好的时候你的消息如果是非数字状态就会报这个错误。推荐作为在源代码中使用数字识别和校正的状态背景。

            String error="{\"Result\":\"ERROR\",\"Message\":"+100+"}";
                    response.getWriter().print(error);
    if (data.Result != 'OK') {
                        if(data.Message == 100){
                            self._showError('未登录!请重新登录');
                        }else{
                            self._showError(data.Message);
                        }
                        //window.location.href="login.jsp";
                        return;
                    }
if (data.Result != 'OK') {
                        if(data.Message == 100){
                            self._showError('未登录!请重新登录');
                        }else{
                            self._showError(data.Message);
                        }
                        //window.location.href="login.jsp";
                        return;
                    }
于 2013-09-23T03:38:32.230 回答
0

通过将值传递给 jtStartIndex、jtPageSize、jtSorting 来解决)谢谢

于 2013-09-25T08:35:54.933 回答