Laravel Datatables不工作,没有错误

时间:2014-06-19 21:56:41

标签: javascript php laravel-4

当我访问该页面时,我只是得到了#34; Processing"但什么也没发生。我看了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

更新: 数据表在我的本地主机上工作正常,但只要我将回购下载到生产服务器就不行。

这是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 [] []

1 个答案:

答案 0 :(得分:0)

我想出了这个问题。我有2个不同版本的datatable.js文件。我猜测变量是相互覆盖的......但是一旦我将所有内容升级到相同的版本,它就会起作用。