2017-09-15 66 views
0

我曾嘗試過幾種方式在AJAX調用後刷新數據表,但無法工作。 我試過draw()和。 ajax.reload()功能,但仍然沒有運氣。 任何想法如何刷新它?如何在ajax調用後刷新數據表

這裏我的代碼

HTML

<table id="transaction_data" class="table table-hover"> 
                <thead> 
                <tr> 
                 <th>Date Created</th> 
                 <th>User Name</th> 
                 <th>Transaction Type</th> 
                 <th>Amount (USD)</th> 
                 <th>Last Update</th> 
                 <th>Status</th> 
                 <th>Amount Coin</th> 
                 <th>Amount Coin Received</th> 
                </tr> 
                </thead> 
                <tbody> 
                <tr> 

                </tr> 
                </tbody> 
               </table> 

數據表腳本

var table = $("#transaction_data").DataTable({ 
      processing: true, 
       serverSide: true, 
       ajax: '{{ url("member/deposit/data_transaction") }}', 
       columns: [ 
        { data: 'created_at', name: 'created_at' }, 
        { data: 'member_id', name: 'member_id' }, 
        { data: 'transaction_type', name: 'transaction_type' }, 
        { data: 'amount_usd', name: 'amount_usd' }, 
        { data: 'updated_at', name: 'updated_at' }, 
        { data: 'status', name: 'status' }, 
        { data: 'amount_coin_kirim', name: 'amount_coin_kirim' }, 
        { data: 'amount_coin_terima', name: 'amount_coin_terima' } 
       ] 
     }); 

AJAX腳本

$('#formdeposit').submit(function(e){ 
    e.preventDefault(); 
    if (grecaptcha.getResponse()) { 

    var formData = { 
      "_token": "{{ csrf_token() }}", 
      'deposit' : $('#deposit').val(), 
      'coin' : $('#coin option:selected').val() 
     }; 
     $.ajax({ 
      type : 'POST', 
      url : '{{ asset("/member/deposit/process") }}', 
      data : formData, 
      dataType : 'json', 
      encode : true 
     }) 
     .done(function(data){ 
       console.log(data); 
       $('#myModal').modal('show'); 
     // 

     if (data.pesan=='ok') 
      { 
      $('#test').html(data.html);  
      } 

     else{ 
      $('#test').html(data.pesan); 
     } 

       }); 

    e.preventDefault(); 
     table.draw(); //here I tried to refresh the datatable 
    } 
    else{ alert('Please Confirm The Captcha') } 
});  
+0

嘗試'$( 「#的Table_id」)ajax.reload();' – Blue

+0

不工作,我想, –

+0

https://stackoverflow.com/questions/5566541/how-to-reload-the -datatablejquery-data – Blue

回答

1

編輯:試試這個(對 - 數據表版本1.10.9 )

$('#formdeposit').submit(function(e){ 
    e.preventDefault(); 
    if (grecaptcha.getResponse()) { 

     var formData = { 
      "_token": "{{ csrf_token() }}", 
      'deposit' : $('#deposit').val(), 
      'coin' : $('#coin option:selected').val() 
     }; 
     $.ajax({ 
      type : 'POST', 
      url : '{{ asset("/member/deposit/process") }}', 
      data : formData, 
      dataType : 'json', 
      encode : true 
     }) 
     .done(function(data){ 


       console.log(data); 
       $('#myModal').modal('show'); 
     // 

     if (data.pesan=='ok') 
      { 
      $('#test').html(data.html);  
      } 

     else{ 
      $('#test').html(data.pesan); 
     } 
     var table = $('#transaction_data').DataTable(); 
     table.ajax.reload(null, false); 

       }); 

     e.preventDefault(); 

     } 
     else{ alert('Please Confirm The Captcha') } 
}); 
+0

@Billy Origin .. ..知道你的版本後編輯我的答案編輯我的答案。 –

+0

感謝它的工作。感謝你的魔力。 –

+0

很高興聽到。歡迎:) –