我在我的项目中使用数据表插件,但它向我显示了一些警告消息
DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4
代码是: html代码:
<table id="userdetails">
<thead>
<tr>
<td>User Login</td>
<td>User NiceName</td>
<td>Email</td>
<td>Register Date</td>
</tr>
</thead>
<table>
ajax调用
<script>
jQuery.ajax({
type : 'POST',
data : {tableName:table_name},
url: '<?php echo plugins_url() . '/pagination/ajaxResponse.php'; ?>',
success: function(data){
jQuery("#userdetails").dataTable({
data:data,
colums:[
{'data':'user_login'},
{'data': 'user_nicename'},
{'data': 'user_email'},
{'data': 'user_registered'},
]
})
}
})
</script>
服务器代码:
$result = $wpdb->get_results("SELECT user_login,user_nicename,user_email,user_registered from ".$_POST['tableName']);
echo json_encode($result);
最佳答案
虽然您从 PHP 文件发送 JSON 格式的数据,但您需要在 AJAX 调用中将其作为 JSON 接受。
您需要进行 2 处修改:
- 将 dataType:'json', 添加到您的 AJAX 调用中,
- 按照 @Terry 的建议将“colums”更改为“columns”
即您的 AJAX 调用应如下所示:
<script>
jQuery.ajax({
type : 'POST',
data : {tableName:table_name},
dataType:'json',
url: '<?php echo plugins_url() . '/pagination/ajaxResponse.php'; ?>',
success: function(data){
jQuery("#userdetails").dataTable({
data:data,
columns:[
{'data':'user_login'},
{'data': 'user_nicename'},
{'data': 'user_email'},
{'data': 'user_registered'},
]
})
}
})
</script>
关于javascript - 数据表显示 :DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, 第 1 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419246/