[英]Laravel delete function with Sweet Alert
So I'm using sweet alert on laravel 5.7.所以我在 Laravel 5.7 上使用甜蜜警报。
I need help as it seems that the function doesn't work after I click the sweet alert confirm button.我需要帮助,因为在单击甜蜜警报确认按钮后该功能似乎不起作用。
my html:我的html:
<button rel="{{ $mail->id }}"" rel1="delete-mail" href="javascript:"
class="deleteMail btn btn-danger btn-xs">Delete</button></td>
my script:我的脚本:
$(".deleteMail").click(function(){
var id = $(this).attr('rel');
var deleteFunction = $(this).attr('rel1');
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
confirmButtonText: 'Yes, delete it!',
buttonsStyling: false
},
function(){
window.location.href='/admin/'+deleteFunction+'/'+id;
});
});
Route:路线:
public function delete($id = null){
if(!empty($id)){
Mail::where(['id'=>$id])->delete();
return redirect()->back()->with('flash_message_success','Surat berhasil dihapus!!');
}
}
I've tried window.location.href
without sweet alert function and it workdc fine.我试过
window.location.href
没有甜蜜的警报功能,它工作正常。
However, when I'm using sweet alert it doesn't work at all.但是,当我使用甜蜜警报时,它根本不起作用。
I can't find any error in console log
.我在
console log
找不到任何错误。 please help.请帮忙。
Try .then function.尝试.then功能。 For example:
例如:
$(".deleteMail").click(function(){
var id = $(this).attr('rel');
var deleteFunction = $(this).attr('rel1');
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
confirmButtonText: 'Yes, delete it!',
buttonsStyling: false
}).then((isConfirm) => {
if (isConfirm){
window.location.href='/admin/'+deleteFunction+'/'+id;
}
});
});
try
尝试
$(".deleteMail").click(function(){
var id = $(this).attr('rel');
var deleteFunction = $(this).attr('rel1');
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
confirmButtonText: 'Yes, delete it!',
buttonsStyling: false
},function(isConfirm){
alert('ok');
});
$('.swal2-confirm').click(function(){
window.location.href='/admin/'+deleteFunction+'/'+id;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.