gpt4 book ai didi

javascript - ajax调用后如何刷新数据表

转载 作者:行者123 更新时间:2023-12-03 03:27:59 25 4
gpt4 key购买 nike

我尝试了几种方法在 AJAX 调用后刷新我的数据表,但不起作用。我尝试了 draw() 和 .ajax.reload() 函数,但仍然没有运气。知道如何刷新它吗?

这是我的代码

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') }
});

最佳答案

编辑:试试这个(对于 - 数据表版本 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') }
});

关于javascript - ajax调用后如何刷新数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46231291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com