Php 405(不允许使用方法)拉维
在尝试使用ajax删除项目时,我在Laravel中得到了一个405(不允许使用方法)。有人请帮忙 这是我的路线Php 405(不允许使用方法)拉维,php,ajax,laravel,Php,Ajax,Laravel,在尝试使用ajax删除项目时,我在Laravel中得到了一个405(不允许使用方法)。有人请帮忙 这是我的路线 Route::get('/home', 'HomeController@index')->name('home'); Route::post('/destroy', 'PagesController@destroy'); Auth::routes(); 这是我的ajax代码 function confirmDelete(id){ //alert(
Route::get('/home', 'HomeController@index')->name('home');
Route::post('/destroy', 'PagesController@destroy');
Auth::routes();
这是我的ajax代码
function confirmDelete(id){
//alert('Delete post id-'+id);
$.ajax({
type: 'post',
url: 'blogs/destroy',
data: {'id' : id},
dataType: 'json',
cache: false,
success: function(res){
console.log("worked");
alert(res);
}
})
}
这是我的控制器
public function destroy (Request $request){
$id = $request->id;
echo json_encode ($id);
// $blog = Blog::findorFail ( $id );
// $blog->delete ();
// return response(['msg'=>'Post deleted',
'status'=>'success']);
// return redirect::to ( '/blogs' )->with ( 'success', 'Post
successfully deleted!' );
}
出现此错误的原因是您的请求URI
/blog/destroy
与路由定义/destroy
不匹配
因此,要么将路线更改为
Route::post('/blog/destroy','PagesController@destroy');
或者改变你的要求
$.ajax({
键入:“post”,
url:“/destroy”,
// ...
})
为路线尝试此选项->
Route::post('/blog/destroy','PagesController@destroy)->(第页)代码>
在ajax中尝试以下方法:
$.ajax({
type: 'post',
url:'{{ route('destroyPage') }}',
// ...
})
得到答案只需登录到我的服务器并禁用ModSecurity及其工作,因此,稍后,我将ModSecurity配置为不在live server上获取405 methods not allowed error。这意味着它现在可以工作,并且您的控制器代码有问题。这是我的控制器。我似乎找不到任何问题。你能告诉我500的错误是另一个问题吗。如果上面的答案对你有帮助(确实如此),那么它应该被提升并标记为接受。投票。我的控制器有问题吗?有人吗?@ElizabethW.Ng'ang'a显示您收到的确切错误消息。您应该能够在日志文件\storage\logs\laravel.log