各位,我需要你们的帮助,我正在做我的最后一年的项目,我遇到了一个问题,这个问题毁了我一整天。甜蜜警报正常显示,但在提交要删除的警报后,它不工作,也不去请求。这是我的按钮和js代码。
提前感谢
提交按钮或锚点
<div class="menu-item px-3">
<a href="#" class="menu-link px-3 delete" id="{{$agent->id}}">Delete</a>
</div>Js代码
<a>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</a>
<script>
$(document).on('click','.delete',function()
{
console.log('hi before');
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value)
{
console.log('hi after');
var id = $(this).attr('id');
var url = '{{ route("agent.destroy", ":agent") }}';
url = url.replace(':agent', id);
$.ajax
({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url:url,
type:'DELETE',
datatype:'json',
data: {
"_method": 'DELETE',
},
success:function(data)
{
location.reload();
}
})
}
})
});
</scrip>发布于 2021-08-05 18:37:23
在母版页的标题部分找到答案和ad csrf meta标签
<meta name="csrf-token" content="{{ csrf_token() }}">https://stackoverflow.com/questions/68667854
复制相似问题