当我单击按钮以显示表更新和新内容时,如何在 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