2017-08-04 56 views
0

我在jQuery數據表中使用服務器端,但行不會添加到table.its來成爲ajax,行也來到數據參數,但它不會添加到表。jQuery數據表中的服務器端響應

otable = $('#siteselectiontable').DataTable({ 
    "serverSide": true, 
    "deferLoading": 0, 
    "processing": true, 
    "paging": true, 
    "columns": [{ 
     "data":"RADIO" 
    }, 
    { 
    "data":"SITE_DATA" 
    } 
    ], 
    "ajax": { 
     success: function(data) { 
      if(typeof data['error']!="undefined"){ 
       bootbox.alert({ 
        closeButton: false, 
        message: "<div class='alert alert-danger' role='alert'>" + 
         "<strong>Timeout Error: </strong>Please refine your search" + 
         "</div>" 
       }); 
      } 
     }, 
     beforeSend: function() { 
      $("#siteselectionfooter").after(progress); 
     }, 
     complete: function() { 
      $(".loading-mask").remove(); 
     } 
    }, 
    "searching": false, 
    "ordering": false, 
    "lengthChange": false, 
    "pageLength": 5, 
    "dom": '<"top"><"pull-right"f>t<"bottom center"p><"clear">', 
    "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
     $('td:eq(0)', nRow).css({ 
      'text-align': 'center', 
      'vertical-align': 'middle' 
     }); 
    } 
}); 

和Ajax調用我使用下面的:

table.ajax.url(url).load(); 

我怎樣才能處理服務器端錯誤的自定義方式?
enter image description here

+0

具有u定義jQuery的數據表的頁眉? – Se0ng11

+0

你的數據表在哪裏? –

+0

我已經定義了頭文件,行也出現了,但是有時候錯誤也出現了,我想以我的方式顯示它,因爲我定義了「成功」,但是在添加行後卻沒有添加到表格中。 – user2841408

回答

0

我已經與阿賈克斯的選項dataSrc解決這一點,並添加以下行

$.fn.dataTable.ext.errMode = 'none';  



"ajax": { 
     beforeSend: function() { 
      $("#siteselectionfooter").after(progress); 
     }, 
     complete: function() { 
      $(".loading-mask").remove(); 
     }, 
     "dataSrc": function (json) { 
      if(typeof json['error']!="undefined"){ 
       bootbox.alert({ 
        closeButton: false, 
        message: "<div class='alert alert-danger' role='alert'>" + 
         "<strong>Timeout Error: </strong>Please refine your search" + 
         "</div>" 
       }); 
      } 
      return json.data; 
     } 
    },