Javascript 我的datatables问题的正确语法是什么?
我有一个数据表,它在脚本中加载,如下所示:Javascript 我的datatables问题的正确语法是什么?,javascript,jquery,ajax,datatables,Javascript,Jquery,Ajax,Datatables,我有一个数据表,它在脚本中加载,如下所示: <script> function table() { $.ajax({ url: 'tables/winnertable-all.php', type: 'get', data: { name: '<?php echo $name ?>', Type: '<?php echo $Type
<script>
function table() {
$.ajax({
url: 'tables/winnertable-all.php',
type: 'get',
data: { name: '<?php echo $name ?>', Type: '<?php echo $Type ?>' },
success: function(response){
$('.winnertable').html(response);
$('#newtable').DataTable();
}
});
}
table();
setInterval(table, 3600000);
table();
setInterval(table, 3600000);
$(document).ready(function() {
$('#newtable').DataTable();
} );
</script>
我想在我的代码中实现这一点,但是我无法在添加行后加载表。
我试过:
<script>
function table() {
$.ajax({
url: 'tables/winnertable-all.php',
type: 'get',
data: { name: '<?php echo $name ?>', Type: '<?php echo $Type ?>' },
success: function(response){
$('.winnertable').html(response);
$('#newtable').DataTable();
"order": [[ 1, "desc" ]];
}
});
}
table();
setInterval(table, 3600000);
table();
setInterval(table, 3600000);
$(document).ready(function() {
$('#newtable').DataTable();
"order": [[ 1, "desc" ]];
} );
</script>
我知道我的语法实现存在问题,但是我尝试了各种不同的方法,但无法使其正常工作。通常,如果要重新初始化数据表以更改其基本设置,则需要使用该标志 但是,在您的情况下,我只需将所需的订单设置添加到默认值 $.extend true、$.fn.dataTable.defaults、{ 订单:[[3,描述]] } 如果您在pageload上预先这样做,所有表的默认顺序都是:[[3,desc]]。如果您出于某种原因不想更改默认值,那么您可以简单地利用API,因为它有一个方法 变量表=$'newtable'。数据表 表3.order[[3,desc]]图纸
您的代码与示例不匹配。该示例在括号内有一个对象-DataTable{order:[[3,desc]]};您的“订单”行不在括号中。除此之外,我不知道是否有任何数据,但该修复程序的顺序应该可以。还要对代码进行格式化;有点难说是怎么回事;由于某些原因重复了两行。您能分享您在控制台中看到的任何错误吗?
<script>
function table() {
$.ajax({
url: 'tables/winnertable-all.php',
type: 'get',
data: { name: '<?php echo $name ?>', Type: '<?php echo $Type ?>' },
success: function(response){
$('.winnertable').html(response);
$('#newtable').DataTable();
"order": [[ 1, "desc" ]];
}
});
}
table();
setInterval(table, 3600000);
table();
setInterval(table, 3600000);
$(document).ready(function() {
$('#newtable').DataTable();
"order": [[ 1, "desc" ]];
} );
</script>