<a class="btn table-btn delete" onclick="return confirm('Are you sure?')" href="/fields/{{ hashid_encode($extrafield->id) }}"></a>
<script>
$('.delete').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var url, data;
url = $(this).attr('href');
data = {
'_method' : 'DELETE',
}
request = $.ajax({
method: "post",
url: url,
data: data
});
});
</script>
我使用laravel所以我的路线看起来像这样:
Route::get('/{id}',['as'=>'fields.show','uses'=>'ResourceController@show']);
Route::delete('/{id}', ['as'=>'fields.destroy','uses'=>'ResourceController@destroy']);
不知道为什么它使用Route :: get而不是Route :: delete,即使我尝试使用post方法请求ajax。我试着发布它
request = $.post({
url: url,
data: data
});