PHP Sweet Alert页面重定向

时间:2017-12-16 10:54:03

标签: php ajax sweetalert2

我使用AJAX使用Sweet Alert进行删除,并在删除后设置了页面重定向。每当我点击删除时,它会询问确认或不按钮, 如果我单击是 - 确认它将删除,并且页面被重定向。我想要 喜欢删除成功消息" OK成功删除"那个时候只有页面被刷新,

 function delete_confirm(id) {
            swal({
                    title: "Are you sure?",
                    text: "You will not be able to recover this Product Attribute!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: '#DD6B55',
                    confirmButtonText: 'Yes, delete it!',
                    cancelButtonText: "No, cancel please!",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            url: "cart-delete.php",
                            type: "POST",
                            data: {
                                id: id,
                            },
                            success: function(data) {
                                console.log(data); 
                                swal("Done!", "It was succesfully deleted!", "success");
                                $('[remove_attr_' + id + ']').parents('.demo-card-wide').remove();
                                  window.location.href = 'add-to-cart.php';
                            }
                        });
                    } else {
                        swal("Cancelled", "Your Product Attribute! is safe :)", "error");
                    }
                });
        };

1 个答案:

答案 0 :(得分:1)

在成功时删除此行

window.location.href = 'add-to-cart.php'; 

写下其他一些动作 恩。关于甜蜜警报关闭行动