我在 View 上有一个像这样的ajax请求方法帖子:
$.ajax({
data: { test : 1337, _token: "{{csrf_token()}}" },
type: "POST",
url: '{{ route("get_image_by_parent_id") }}',
success: function (res) {
console.log(res)
},
});
这是我的路线代码:
Route::post('backend/blog/get_image_by_parent_id', 'Backend\BlogController@get_image_by_parent_id')->name('get_image_by_parent_id');
这是我的 Controller :
public function get_image_by_parent_id(Request $request)
{
echo json_encode($request);
}
当我查看网络选项卡时,它显示如下:
有人可以帮我吗?
最佳答案
echo json_encode($request);
这是不正确的,因为请求对象不直接保存您的请求数据。它是变量中许多其他东西的集合-
如果您想访问所有请求,那么我建议您这样做 -
$request->all();
您可以根据需要使用 dump() 或 dd() 在控制台上打印输出。
dump($request->all());
关于jquery - Laravel Ajax 请求 $request 空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54936994/