您确定将 AJAX 调用指向正确的方向吗?
list.blade.js
javascript 指向当前页面,因为它是同一个 URL,只是协议不同。如果您将其放在另一个页面上,它将无法按原样工作。您必须将其指向$this->crud->route
,仍然使用 DELETE 方法。所以是这样的:
function register_delete_button_action() {
$("[data-button-type=delete]").unbind('click');
// CRUD Delete
// ask for confirmation before deleting an item
$("[data-button-type=delete]").click(function(e) {
e.preventDefault();
var delete_button = $(this);
var delete_url = '{{ url($this->crud->route) }}'; <---- notice the change here
if (confirm("{{ trans('backpack::crud.delete_confirm') }}") == true) {
$.ajax({
url: delete_url,
type: 'DELETE',
success: function(result) {
// Show an alert with the result
new PNotify({
title: "{{ trans('backpack::crud.delete_confirmation_title') }}",
text: "{{ trans('backpack::crud.delete_confirmation_message') }}",
type: "success"
});
// delete the row from the table
delete_button.parentsUntil('tr').parent().remove();
},
error: function(result) {
// Show an alert with the result
new PNotify({
title: "{{ trans('backpack::crud.delete_confirmation_not_title') }}",
text: "{{ trans('backpack::crud.delete_confirmation_not_message') }}",
type: "warning"
});
}
});
} else {
new PNotify({
title: "{{ trans('backpack::crud.delete_confirmation_not_deleted_title') }}",
text: "{{ trans('backpack::crud.delete_confirmation_not_deleted_message') }}",
type: "info"
});
}
});
}