我曾嘗試過幾種方式在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') }
});
嘗試'$( 「#的Table_id」)ajax.reload();' – Blue
不工作,我想, –
https://stackoverflow.com/questions/5566541/how-to-reload-the -datatablejquery-data – Blue