簡體   English   中英

如何在Laravel 5.2中獲取AJAX表記錄

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

當我單擊按鈕以顯示要更新的表和新內容時,如何在AJAX Laravel上下文中顯示所有記錄。但是此代碼對我不起作用。

我的桌子:

<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>

我的控制器:

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

我的ajax代碼:

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

在控制器中沒有ajax的情況下使用以下代碼:

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

在這種情況下,您不能使用@foreach,因為您的數據是js,請在此示例中看看https://gist.github.com/triceam/3407134

在我的包中也https://github.com/marcosrjjunior/lvlgrid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM