如何在 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
相关文章:
- 获取ajax加载的图像的大小
- 在foreach中获取ajax结果
- 获取ajax请求的请求头
- 使用Pebble.js获取AJAX请求时出错
- 如何在使用 DATATABLES 发送到模板之前获取 AJAX 响应
- 获取 ajax 创建的复选框的值
- 是否可以在其他文件中获取 AJAX 成功变量的值
- 获取AJAX中未定义的值(x),web api
- 无法获取 AJAX 响应
- 如何获取ajax调用返回的元素数
- 可以't获取ajax请求jquery,什么也没发生
- 如何从成功中获取 ajax 响应并使用 jQuery 将其分配给变量中
- 可以't获取AJAX发送的phpPOST
- 如何用纯javascript获取ajax请求的ContentType
- 使用PHP获取AJAX或js操作后的文档源
- Flexigrid正在获取ajax响应
- 获取ajax post请求中传递的参数
- 获取 ajax 在 laravel 中发布数据
- 无法获取 AJAX 表单来提交 MySQL 数据
- 获取 ajax 发布请求的用户输入