2013-03-20 32 views
2

在我的代碼中使用jTable在jquery modile中,我從查詢字符串中獲取參數並綁定到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是

[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', {.. on pageload?

編輯:

即時得到這個消息客棧響應 { 「消息」: 「無效的Web服務調用,缺少參數值:\ u0027org \ u0027。」, 「堆棧跟蹤」:」在System.Web程序。 Script.Services.WebServiceMethodData.CallMethod(Object target,IDictionary 2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary 2 parameters)\ r \ n System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n System .Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData)「,」ExceptionType「:」System.InvalidOperationException「}

+0

可能的路徑解決:的listAction: 「SearchResult.aspx/GetSearch」 是不正確,請檢查。 – 2013-03-20 12:36:25

+0

我在ajax調用的幫助下檢查了它,它是工作函數Getdata()var pageUrl ='<%= ResolveUrl(「〜/ SearchResult.aspx」)%>' var DTO =「{org:'」('<%= Request [「org」]%>')+「',catchword:'」+('<%= Request [「tm」]%>')+「'」「; $ .ajax({type:「POST」, url:pageUrl +「/ GetSearch」, – Fluminda 2013-03-20 13:01:21

+1

根據你的錯誤信息,你沒有正確傳遞一個值 – 2013-03-20 13:13:51

回答

0

通過傳遞值jtStartIndex,jtPageSize,jtSorting)謝謝

3

您不通過g組織和流行語參數的任何值。您可以使用listAction來執行此操作:「SearchResult.aspx/GetSearch?org = asd & catchword = asd」

此外,您可以使用firebug或chrome開發工具檢查網絡軟件包以查看錯誤詳細信息。

+0

解決傳遞值到jtStartIndex,jtPageSize,jtSorting) 謝謝 – Fluminda 2013-04-08 13:02:45

1

JTable執行結果,有兩個狀態標識,ok和其他。當國家是!好的,當你的消息將被報告,如果一個非數字狀態這個錯誤。建議在源代碼中使用數字識別和校正作爲狀態背景。

  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; 
        } 
相關問題