2012-02-27 122 views
0

我需要發送JSON字符串化格式的定製數據以及每個調用服務器的ajax常規數據。jQuery dataTables - 將json字符串化數據傳遞到服務器

這裏是我的javascript代碼,

$('#dataList').dataTable({ 
     "bFilter": false, 
     "bSort": false, 
     "bAutoWidth": true, 
     "iDisplayLength": 20, 
     "sPaginationType": "full_numbers", 
     "bProcessing": true, 
     "bServerSide": true, 
     "sAjaxSource": "/ViewGenerator/GetPagedViewData", 
     "sServerMethod": "POST", 
     "fnServerParams": function (aoData) { 
      var name = $('#viewName').val(); 
      var viewId = $('#viewId').val(); 
      var description = $('#viewDescription').val(); 
      var viewInfo = JSON.stringify(currentviewInfo); 
      aoData.push({ "name": "viewId", "value": viewId }); 
      aoData.push({ "name": "viewName", "value": name }); 
      aoData.push({ "name": "viewDescription", "value": description }); 
      aoData.push({ "name": "viewInfo", "value": viewInfo }); 
     }, 
     "fnRender": function (oObj) { 
      for (var i = 0; i < oObj.length; i++) { 
       console.log(oObj[i]); 
      } 
     } 
    }); 

控制器的簽名是:

public JsonResult GetPagedViews(int? iDisplayStart = 0, int? iDisplayLength = 0, int? sEcho = 0, string viewId = null, string viewName = null, string viewDescription = null, viewInfo viewInfo = null) 
    { 

時,我認爲Chrome開發工具的JS錯誤,我發現一個錯誤的請求(400)由, 我無法找到多功能代碼的確切位置。另外,我如何設置應用程序類型爲每個數據表ajax調用的應用程序/ json。

+0

這有點晚,但你有沒有設法解決你的問題? – 2012-07-17 14:41:32

+0

@BrendanVogt:謝謝Brendan,我已經使用fnServerData Ajax Call修復了這個問題。無論如何,你可以在這裏發佈你的解決方案,以便我們可以分享我們的方式來處理這個問題。我也會發布我的。 – Saravanan 2012-07-18 04:27:08

回答

0

經過探索,我遇到了fnServerData Ajax調用選項。藉助此API,我能夠完成此任務。更多詳細信息here

相關問題