我使用DataTable显示数据但数据查询失败。这是DataTable代码:
$('#table_id').DataTable( {
ajax:{
url: './datasource02.php'
},
"columns": [
{ "data": "name", "name": "name", "title": "Name", },
{ "data": "email", "name": "email", "title": "Email" },
{ "data": "coupon_id", "name": "coupon_id", "title": "Coupon" },
{ "data": "coupon_off", "name": "coupon_off", "title": "Discount" },
],
"dom": 'lfrtipB',
"destroy": 'true',
"buttons": {
"dom": {
"button": {
"tag": "button",
"className": "btn"
}
},
"buttons": [
{ extend: 'copy', text: 'Copy' },
{ extend: 'csv', text: 'CSV' },
{ extend: 'excel', text: 'Excel' },
{ extend: 'pdf', text: 'PDF' },
{ extend: 'print', text: 'Print' }
]
}
} );
我得到的错误是:
DataTables警告:table id = table_id - Ajax错误。有关此错误的详细信息,请参阅http://datatables.net/tn/7
datasource02.php?_ = 1510684591408
请求方法:GET
状态代码:404 Not Found
发起人:jquery.min.js:4
答案 0 :(得分:0)
首先,提供的信息不足以指导您解决方案,例如:您还没有提供目录结构。 以下是几个问题。
datasource02.php
所在的位置(服务器中文件的路径)?所以,404肯定是一个URL问题,这意味着,你要找的文件不存在。
调试建议:您可以在地址栏中打开文件http://website.com/path/to/datasource02.php
,看看是否有200
响应。同时修改代码如下。
$('#table_id').DataTable( {
ajax:{
url: 'http://website.com/path/to/datasource02.php'
},
"columns": [
{ "data": "name", "name": "name", "title": "Name", },
{ "data": "email", "name": "email", "title": "Email" },
{ "data": "coupon_id", "name": "coupon_id", "title": "Coupon" },
{ "data": "coupon_off", "name": "coupon_off", "title": "Discount" },
],
"dom": 'lfrtipB',
"destroy": 'true',
"buttons": {
"dom": {
"button": {
"tag": "button",
"className": "btn"
}
},
"buttons": [
{ extend: 'copy', text: 'Copy' },
{ extend: 'csv', text: 'CSV' },
{ extend: 'excel', text: 'Excel' },
{ extend: 'pdf', text: 'PDF' },
{ extend: 'print', text: 'Print' }
]
}
} );