DataTables json未处理(在Laravel中) [英] DataTables json is not processed (in Laravel)
问题描述
Datatables对其请求的json不执行任何操作
Datatables does nothing with the json it requested
我正在使用Yajra的数据表填充我的表,而这本书我做了一切.控制器设置正确,路由是正确的(如果我输入了创建数据库的控制器功能的指定路由,则可以以所需格式看到所需的json:
I am using Yajra's Datatables to populate my table and I did everything by the book. The controller is set up correctly, the routes are good (if I enter the route designated to the controller function which creates the Database, I can see the desired json in the desired format:
{"draw":0,
"recordsTotal":44,
"recordsFiltered":44,
"data":[{
"agency":"agency",
"number":"20966512",
"name":"Name John",
"value":"28.22",
}]
}
这是我用来创建数据表的.js代码:
This is the .js code that I use to create my datatable:
$(document).ready(function() {
$('#tbl').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route("datatable") !!}',
columns: [
{data: 'agency', name: 'agency'},
{data: 'number', name: 'number'},
{data: 'name', name: 'name'},
{data: 'value', name: 'value'},
]
});
});
我收到一个错误提示:
DataTables警告:表id = tbl-Ajax错误.有关此错误的更多信息,请参见 http://datatables.net/tn/7 >
在控制台中查看时,出现以下错误:
When I look in the console I get the following error:
{
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "/home/vagrant/Projects/Uniqa-ACB/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 179,
"trace": etc...
}
Laravel 5.8, PHP 7.3, Yajra DT:6 datatables.net:1.10
Laravel 5.8, PHP 7.3, Yajra DT: 6, datatables.net: 1.10
预先感谢您,如果您需要更多代码,我很乐意输入.
Thank you in advance, if you need any more code I wil gladly input it.
推荐答案
尝试访问的路由包含完整的json,并带有一些奇怪的编码,我将路由直接更改为"/datatables",并按照下面的建议进行操作,我还将发布类型指定为GET,现在正在填充表.谢谢.
The route that was trying to access contained the full json with some weird encoding on it, I changed the route to "/datatables" directly and as recommended bellow, I also specified the post type to GET, and now the tables are being populated. thank you.
这篇关于DataTables json未处理(在Laravel中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!