[英]Datatable showing :DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, column 1
I am using datatable plugin in my project but it showing me some warning message我在我的项目中使用了数据表插件,但它向我显示了一些警告消息
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
DataTables 警告:table id=userdetails - 为第 0 行、第 1 列请求未知参数“1”。有关此错误的更多信息,请参阅http://datatables.net/tn/4
code is: Html code:代码是: 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 call 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>
server code:服务器代码:
$result = $wpdb->get_results("SELECT user_login,user_nicename,user_email,user_registered from ".$_POST['tableName']);
echo json_encode($result);
Though you are sending data in JSON format from PHP file, you need to accept it as JSON in AJAX call.虽然您从 PHP 文件以 JSON 格式发送数据,但您需要在 AJAX 调用中将其作为 JSON 接受。
You need to do 2 modifications:你需要做2个修改:
ie your AJAX call should look like:即您的 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>
Insert this code JS ajax to add error handle.插入此代码 JS ajax 以添加错误句柄。 Also get a correct json from entityframework.
还可以从 entityframework 中获取正确的 json。
jQuery.ajax({
type: 'GET',
dataType: 'json',
url: 'https://localhost:44361/api/car',
success: function (data) {
var data = jQuery.parseJSON(data);
console.log(data);
jQuery("#tableAPI").dataTable({
data: data,
columns: [
{ 'data': 'vin' },
{ 'data': 'marca' },
{ 'data': 'tipo' },
{ 'data': 'fechaEmsablado' }
]
})
},
error: function(e,message){
jQuery("#tableAPI").dataTable({
}),
alert(message);
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.