【发布时间】:2020-03-15 19:58:08
【问题描述】:
我试图在我的 laravel 控制器函数中获取由 Jquery Ajax POST 请求发送的数据,但我无法获取数据并显示。 这是ajax请求
deleteImg=function(id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
$.ajax({
url: "/admin/gallery/deleteFile",
method: 'POST',
data:{'id':id},
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success: function (res) {
console.log(res);
}
});
}
这是控制器方法
public function deleteFile(Request $req)
{
$id=$req->id;
if($id)
{
die('done');
}
die('without');
}
这是路由文件
Route::get('gallery', 'GalleryController@index');
Route::post('gallery/saveImage', 'GalleryController@saveImage');
Route::get('gallery/getFiles', 'GalleryController@getFiles');
Route::post('gallery/deleteFile', 'GalleryController@deleteFile');
它给出“没有”作为响应。谁能告诉我我在哪里犯了错误。提前致谢。
【问题讨论】:
-
请发布您的路线
-
请贴出你的路线代码,一定有错误。
-
尝试
data: { id }发送请求正文,如id=123 -
@PrabhjotSinghKainth 如果路由文件中存在错误,则它不会响应“没有”。我已经分享了路线文件
-
@Utkarsh 尝试 print_r($r) 检查它是否接收到任何数据