【问题标题】:Laravel Datatables NOT working, NO errorLaravel 数据表不工作,没有错误
【发布时间】:2014-08-10 14:20:50
【问题描述】:

当我访问该页面时,我只是得到“正在处理”,但什么也没发生。我查看了 chrome 中的 javascript 控制台,我没有收到任何错误。所以我做错了什么,但我不知道它是什么。起初我以为是 JSON 输出格式不正确,但我对照 jsonlint.com 检查了它

我确定这是一件简单的事情,我正在寻找...拜托?

博客数据控制器

public function data()
{
    $posts = Post::select(array('posts.id', 'posts.title', 'posts.id as comments', 'posts.created_at'));
    return Datatables::of($posts)
    ->edit_column('comments', '{{ DB::table(\'comments\')->where(\'post_id\', \'=\', $id)->count() }}')
    ->add_column('actions', '<a href="{{{ URL::to(\'admin/blog/\' . $id . \'/edit\' ) }}}" class="btn btn-default btn-xs iframe" >{{{ Lang::get(\'button.edit\') }}}</a>
            <a href="{{{ URL::to(\'admin/blog/\' . $id . \'/delete\' ) }}}" class="btn btn-xs btn-danger iframe">{{{ Lang::get(\'button.delete\') }}}</a>
        ')
    ->remove_column('id')
    ->make();
}

javascript:

<table id="posts" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>ID</th>
            <th>Title</th>
            <th>Content</th>
            <th>Created</th>
            <th>{{{ Lang::get('table.actions') }}}</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
@stop

@section('scripts')
<script type="text/javascript">
    var oTable;
    $(document).ready(function() {
            oTable = $('#posts').dataTable({
            "sDom": "<l><f><r>t<i><p>",
            "sPaginationType": "bootstrap",
            "oLanguage": {
                "sSearch": "Search:",
                "sLengthMenu": "_MENU_ records per page"
            },
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "{{ URL::to('admin/blog/data') }}"
        });

        $("#users_filter input").addClass("form-control inline-control input-sm");
        $("#users_length select").addClass("form-control inline-control");
    });
</script>
@stop

更新: 数据表在我的本地主机上工作得很好,但是一旦我将 repo 拉到我的生产服务器上它就不起作用了。

这是json数据

{"sEcho":0,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[[1,"First Post","<p>Welcome to my new blog. It&#39;s still under development and there are constantly changes being made. Just today i got CKEditor working on my blog admin, so that i could put HTML into my posts. Thi...<\/p>","1","2014-06-08 04:12:14","<a href=\"http:\/\/www.asdasd.com\/admin\/blog\/1\/edit\" class=\"btn btn-default btn-xs iframe\" >Edit<\/a>\n                <a href=\"http:\/\/www.asdaf.com\/admin\/blog\/1\/delete\" class=\"btn btn-xs btn-danger iframe\">Delete<\/a>\n            "],[2,"second","yep its working","1","2014-06-08 05:58:13","<a href=\"http:\/\/www.asdaf.com\/admin\/blog\/2\/edit\" class=\"btn btn-default btn-xs iframe\" >Edit<\/a>\n                <a href=\"http:\/\/www.asdaf.com\/admin\/blog\/2\/delete\" class=\"btn btn-xs btn-danger iframe\">Delete<\/a>\n            "]],"sColumns":["posts.id","posts.title","posts.content","posts.id as comments","posts.created_at","actions"],"aQueries":[{"query":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":1.1},{"query":"select `roles`.*, `assigned_roles`.`user_id` as `pivot_user_id`, `assigned_roles`.`role_id` as `pivot_role_id` from `roles` inner join `assigned_roles` on `roles`.`id` = `assigned_roles`.`role_id` where `assigned_roles`.`user_id` = ?","bindings":[1],"time":0.99},{"query":"select `posts`.`id`, `posts`.`title`, `posts`.`content`, `posts`.`id` as `comments`, `posts`.`created_at` from `posts`","bindings":[],"time":3.98},{"query":"select count(*) as aggregate from `comments` where `post_id` = ?","bindings":[1],"time":2.34},{"query":"select count(*) as aggregate from `comments` where `post_id` = ?","bindings":[2],"time":0.73}]}

这里是 app/storage/logs/log-cgi-fcgi-2014-06-21.txt

[2014-06-21 22:19:30] production.INFO: index [] []
[2014-06-21 22:19:31] production.INFO: data [] []

【问题讨论】:

  • 你用的是什么包?
  • bllim/laravel4-datatables-package
  • 直接在浏览器中访问admin/blog/data 会得到什么?
  • 经过 jsonlint 验证的正确 json 输出。
  • 所以它适用于我的本地主机,但它不适用于我的生产环境。它与 git repo 完全相同。数据表是否有某种用于开发和生产的配置?

标签: javascript php laravel-4


【解决方案1】:

我发现了这个问题。我有 2 个不同版本的 datatable.js 文件。我猜变量正在相互覆盖......但是一旦我将所有内容升级到相同的版本,它就可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    相关资源
    最近更新 更多