Yajra Datatables包装用于Laravel deosnt正常工作与laravel 5.2 [英] Yajra Datatables Package for Laravel deosnt work properly with laravel 5.2

查看:653
本文介绍了Yajra Datatables包装用于Laravel deosnt正常工作与laravel 5.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了yajra / laravel-datatables-oracle〜6.0软件包,用于支持服务器端数据库,在laravel 5.2中以MySql作为数据库。
我试图显示用户的数据:

I have installed yajra/laravel-datatables-oracle "~6.0" package for supporting server-side datatables in laravel 5.2 with MySql as database. i'm trying to display the datatable of users:

//routes.php
Route::group(['middleware' => ['web'], 'prefix' => 'user'], function () {
    Route::get('/index', 'UserController@index')->name('user.index');
});

这里是我的控制器:

//UserController.php
public function index()
{
    return view('user.index');
}

public function indexData()
{
    $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get();
    return Datatables::of($users)->make();
}

视图:

// user\index.blade.php
@extends('layouts.base')

@section('additional_styles')
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css">
@endsection

@section('additional_scripts')
    <!-- DataTables -->
    <script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
    <script>
        $('#users-table').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": '{!! route('user.index') !!}',
            "columns": [
                {data: 'id', name: 'id'},
                {data: 'name', name: 'name'},
                {data: 'email', name: 'email'},
                {data: 'created_at', name: 'created_at'},
                {data: 'updated_at', name: 'updated_at'}
            ]
        });
    </script>
@endsection


@section('main-content')
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <table class="table table-bordered" id="users-table">
                            <thead>
                            <tr>
                                <th>Id</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Created At</th>
                                <th>Updated At</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

但数据表无法正常工作。在处理数据后,它会向我发出一个警告,指出该响应具有无效的JSON格式,并表示要查看 datatables.net/ tn / 1 。我试图看到chrome的开发工具,看到响应,但我couldnt!

but the datatable doesn't work properly. after processing to render tha data, it show me an alert that the response have invalid JSON format and says to see datatables.net/tn/1. I have tried to see whithin the developer tools of chrome to see the response but i couldnt!

任何关于这个问题的想法?

any idea about the issue ?

推荐答案

现在在laravel中的工作5.2.31,

now its work in laravel 5.2.31,

`        Route
    Route::get('datatables',['uses'=>'DatatablesController@getIndex', 'as' => 'datatables']);
    Route::get('datatables/{data}',['uses'=>'DatatablesController@anyData', 'as' => 'datatables.data']);

    Controller
      public function anyData()
        {
           $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get();
        return Datatables::of($users)->make();
        }

    JS
    $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '{!! url('datatables/data') !!}'
        });`

这篇关于Yajra Datatables包装用于Laravel deosnt正常工作与laravel 5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆