简体   繁体   English

如何在Laravel 5.2中获取AJAX表记录

[英]How to Get AJAX Table Records in Laravel 5.2

How do I display all records in the context of AJAX Laravel when I click the button to display the table be updated and new content.But not work this code for me. 当我单击按钮以显示要更新的表和新内容时,如何在AJAX Laravel上下文中显示所有记录。但是此代码对我不起作用。

my table: 我的桌子:

<table class="table table-condensed text-right">
                <thead class="">
                <tr>
                    <th class="text-right">remove</th>
                    <th class="text-right">edit</th>
                    <th class="text-right">name</th>
                    <th class="text-right">#</th>
                </tr>
                </thead>
                <tbody>
                @foreach($category as $cat)
                    <tr id="append">
                        <td><a id="destroy" href="{{action('categoryController@destroy', [$cat->id])}}"><span
                                        class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
                        <td><a href="{{action('categoryController@update',[$cat->id])}}"><span
                                        class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></td>
                        <td><a href="{{action('categoryController@show', [$cat->id])}}">{{$cat->category}}</a>
                        </td>
                        <th class="text-right">{{$cat->id}}</th>
                    </tr>
                @endforeach
                </tbody>
            </table>

my controller: 我的控制器:

public function index2($request)
{
    $category = Category::table($request->all())->get();
    return ['id'=>$category];
}

my ajax code: 我的ajax代码:

                    $.ajax({
                    type: 'get',
                    url: '{!! URL::route('index2') !!}',
                    data: data,
                    success: function(data){
                        alert(data);
                    }
                })

use this code without ajax in controller: 在控制器中没有ajax的情况下使用以下代码:

    public function index()
{
    $category = Category::all();
    return view('admin.category', compact('category'));
}

you can't use @foreach in this case, because your data are js, take a look in this example https://gist.github.com/triceam/3407134 在这种情况下,您不能使用@foreach,因为您的数据是js,请在此示例中看看https://gist.github.com/triceam/3407134

in my package too https://github.com/marcosrjjunior/lvlgrid 在我的包中也https://github.com/marcosrjjunior/lvlgrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM