10 2 | 我试图用jQuery做一个POST请求,但是我得到错误405(方法不允许),我使用Laravel 5 这是我的代码: jQuery的
HTML
调节器
Jquery错误是http://localhost/laravel5.1/public/empresas/eliminar/5 405(方法不允许)。 url值是
数据值为
如果我改变 任何人都可以帮助我 谢谢。 编辑!! 路线
| ||||
|
15 | 该 您的表单设置为提出
| |||
2 | 您的routes.php文件需要正确设置。 我假设你目前的设置是:
或者其他的东西。为删除方法定义路由。
现在如果使用Route资源,则用于“DELETE”方法的默认路由名称为.destroy。在该函数中定义您的删除逻辑。 | ||
Im trying to do a POST request with jQuery but im getting a error 405 (Method Not Allowed), Im working with Laravel 5
THis is my code:
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>
HTML
{!! Form::open(['route' => ['companiesDelete', ':USER_ID'], 'method' =>'DELETE', 'id' => 'formDelete']) !!}
{!!Form::close() !!}
Controller
public function delete($id, \Request $request){
return $id;
}
The Jquery error is http://localhost/laravel5.1/public/empresas/eliminar/5 405 (Method Not Allowed).
The url value is
http://localhost/laravel5.1/public/empresas/eliminar/5
and the data value is
_method=DELETE&_token=pCETpf1jDT1rY615o62W0UK7hs3UnTNm1t0vmIRZ.
If i change to $.get
request it works fine, but i want to do a post request.
Anyone could help me?
Thanks.
EDIT!!
Route
Route::post('empresas/eliminar/{id}', ['as' => 'companiesDelete', 'uses' => 'CompaniesController@delete']);