gpt4 book ai didi

javascript - $.ajax 发送后 jQuery 刷新表

转载 作者:行者123 更新时间:2023-12-03 02:56:11 28 4
gpt4 key购买 nike

我有一个 $.ajax 函数,需要在发送请求后刷新表,成功后,收到请求后需要再次刷新表。我在收到成功后成功刷新表,但我不知道如何在发送 ajax 并等待接收成功或错误时刷新表。

               /* SHOW - message */
sweetAlert({
title: 'Are You Sure?',
html: message+" <b>"+window.server+"</b> Server?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then(function() {
/* SERVER - data */
var data = {};
data.id = window.id;
data.type = window.type;

/* GET - server install */
$.ajax({
type: 'POST',
url: '/api/server_manage',
data: data,
dataType: 'json',
success: function(res){
console.log('refresh table...');
$('#basicDataTable').dataTable().fnDraw(false);
}
})
}).catch(swal.noop);

所以简而言之,需要这样做:

ajax请求发送...正在等待...刷新表...ajax请求收到成功或错误...刷新表...

如果我将刷新放在ajax之前或之后,那就不好了,因为它从需要在数据表中显示的mysql数据库值中读取数据表..并且其值在调用时设置ajax

最佳答案

数据表可以如 https://datatables.net/examples/data_sources/server_side.html 中的示例所示进行馈送和 https://datatables.net/reference/option/ajax

按如下方式更改代码:

           /* SHOW - message */
sweetAlert({
title: 'Are You Sure?',
html: message+" <b>"+window.server+"</b> Server?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then(function() {
/* SERVER - data */
var data = {};
data.id = window.id;
data.type = window.type;

/* GET - server install */

$('#basicDataTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "/api/server_manage",
"type": "POST"
"data": data,
"dataType": "json"
}
});

}).catch(swal.noop);

关于javascript - $.ajax 发送后 jQuery 刷新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47607161/

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