当我单击按钮显示更新的表和新内容时,如何在 AJAX Laravel 上下文中显示所有记录。但此代码对我不起作用。
我的 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>
我的 Controller :
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);
}
})
在 Controller 中使用此代码而不使用ajax:
public function index()
{
$category = Category::all();
return view('admin.category', compact('category'));
}
最佳答案
这种情况下你不能使用@foreach,因为你的数据是js,看一下这个例子https://gist.github.com/triceam/3407134
关于javascript - 如何在 Laravel 5.2 中获取 AJAX 表记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35829981/