2014-06-14 50 views
0

我有,供應及包括身份證結果和jsonrpc鍵OFA JSON字符串給出的模式rerurns JSON一個JSON RPC服務器使用返回的JSON的給定部分製作jQuery的數據表中提取,並從RPC服務器

{ 
jsonrpc: "2.0" 
id: "1" 
result: "{"iTotalDisplayRecords":"2","iTotalRecords":"2","aaData": [["1","Kenya","Nairobi","0","34"],["2","USA","New York","70","38"]],"sEcho":0}" 
} 

現在問題就來了在響應進來的Web瀏覽器後的DataTable剛剛從服務器永遠

我試圖嘗試添加顯示裝載儀數據

..."sAjaxDataProp":"",... 

但導致找不到匹配的行。我在Rpc服務器中使用了與cgi腳本相同的coe,並發現我得到了所需的輸出,並且表格填充得很好。從腳本JSON響應是

{"iTotalDisplayRecords":"2","iTotalRecords":"2","aaData":[["1","Kenya","Nairobi","0","34"],["2","USA","New York","70","38"]],"sEcho":1} 

我想以某種方式告訴給數據表只選擇jsonrpc請求的結果的一部分,以顯示返回的數據符合市場預期。

這裏是我的javascript發送datapart

oTable=$('#ip_data').dataTable({ 
          "bProcessing": true, 
          "bServerSide": true, 
          "bPaginate": true, 
          "bScrollCollpase": true, 
          "sScrollY": "200px", 
          "sAjaxSource": "/url", 
          "fnServerData": function (sSource, aoData, fnCallback, oSettings) { 
           aoData.push({"name":"method","value":"datatables"}); 
           aoData.push({"name":"id","value":"1"}); 
           oSettings.jqXHR = $.ajax({ 
            "dataType":"json", 
            "type":"GET", 
            "url":sSource, 
            "data":aoData, 
            "success":fnCallback 
           });//END OF AJAX               
        }//END OF FNSERVERDATA 
      });//END OF DATATABLE 

回答

0

首先,使用數據表1.10(和更新你的語法!)https://datatables.net/upgrade/1.10-convert

其次,閱讀本https://datatables.net/manual/server-side 然後閱讀本https://datatables.net/reference/option/ajax

您的解決方案可能最終看起來像

var oTable = $('#ip_data').DataTable({ 
    "serverSide": true, 
    "ajax": { 
     "url": "/url", 
     "data": { 
      "method": "datatables", 
      "id": "1", 
     } 
    }, 
}); 
+0

通過使用console.log(json.result)我得到所需的響應。爲什麼fnCallback沒有填充表格,當我給它的json.result的參數,就像這個「成功」:function(json){console.log(json.result); fnCallback(json.result);說無法讀取未定義的屬性「長度」 –

+0

同樣的問題... – diank

相關問題