错误 405 (方法不允许) Laravel 5
我尝试使用jQuery执行POST请求,但我收到错误405(方法不允许),我正在使用Laravel 5
这是我的代码:
jQuery
<script type="text/javascript">
$(document).ready(function () {
$('.delete').click(function (e){
e.preventDefault();
var row = $(this).parents('tr');
var id = row.data('id');
var form = $('#formDelete');
var url = form.attr('action').replace(':USER_ID', id);
var data = form.serialize();
$.post(url, data, function (result){
alert(result);
});
});
});
</script>
断续器
{!! Form::open(['route' => ['companiesDelete', ':USER_ID'], 'method' =>'DELETE', 'id' => 'formDelete']) !!}
{!!Form::close() !!}
控制器
public function delete($id, \Request $request){
return $id;
}
Jquery 错误 http://localhost/laravel5.1/public/empresas/eliminar/5 405(方法不允许)。
网址值为
http://localhost/laravel5.1/public/empresas/eliminar/5
并且数据值为
_method=DELETE&_token=pCETpf1jDT1rY615o62W0UK7hs3UnTNm1t0vmIRZ.
如果我改变请求它工作正常,但我想做一个帖子请求。$.get
任何人都可以帮我吗?
谢谢。
编辑!!
路线
Route::post('empresas/eliminar/{id}', ['as' => 'companiesDelete', 'uses' => 'CompaniesController@delete']);