我在表中的按钮是通过以下方式创建的:
<div class="logo">
<div class="logo_png"><a href="#"><img src="https://www.w3schools.com/tags/smiley.gif"></a></div>
</div>
js函数:
return Datatables::of($members)
->addColumn('action', function ($id) {
return '<a href="member/' . $id->id . '/edit" class="btn btn-primary">Edit</a>
<button class="btn btn-primary btn-delete" data-remote="/admin/members/' . $id->id . '">Delete</button>
'; })->make(true);
例如,调试警报的返回是:/ admin / members / 2
这条路线是
$('#datatable-member').on('click', '.btn-delete[data-remote]', function (e) {
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var url = $(this).data('remote');
alert(url);
$.ajax({
url: url,
type: 'DELETE',
dataType: 'json',
data: {method: '_DELETE', submit: true}
}).always(function (data) {
$('#datatable-member').DataTable().draw(false);
});
});
我在 JS控制台中出现此错误:
DELETE | admin/members/{member} | members.destroy | App\Http\Controllers\Admin\MemberController@destroy | web
...当然,删除操作不起作用...