我可以通过ajax使用资源吗?我有这个资源
Route::resource('dashboard', 'DashBoardController');
js file
$.ajax({
type: 'delete',
dataType: 'json',
data: {id:id},
url: " {!! route('dashboard.destroy') !!} ",
success: function (data) {
//
}
});
但我收到,
RouteCollection.php 第 161 行中的 NotFoundHttpException:
destroy 方法使用DELETE request
,但它实际上使用POST
请求在一个_method
作为参数,所以你的javascript
部分应如下所示:
$.ajax({
type: 'POST',
dataType: 'json',
data: {
id: id,
_method: 'DELETE'
},
url: "{!! route('dashboard.destroy') !!}",
success: function (data) {
//
}
});
参考:https://laravel.com/docs/5.2/routing#form-method-spoofing https://laravel.com/docs/5.2/routing#form-method-spoofing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)