在脚本开头显示带有Sweet Alert的消息

时间:2018-10-13 07:22:32

标签: php jquery html

我想显示消息"successfully deleting data"并显示“甜蜜警报”和脚本的开头:

<a href="delete.php?&id=<?php echo $r['id']; ?>" class="delete-link">Delete</a>  

javascript:

jQuery(document).ready(function($) {
    $('.delete-link').on('click', function() {
        var getLink = $(this).attr('href');
        swal({
            title: 'Alert',
            text: 'Delete?',
            html: true,
            confirmButtonColor: '#d9534f',
            showCancelButton: true,
        }, function() {
            window.location.href = getLink
        });
        return false;
    });
});

数据已成功删除,但是我想要显示数据消息的方式已被删除,它放在哪里?

swal("Success!", "Successfully Deleted Data!", "success");

1 个答案:

答案 0 :(得分:0)

我对Sweetalert不太了解,但是据我估计swal函数的第二个参数是确认动作!

因此您可以在确认true后使用jquery ajax删除它:

jQuery(document).ready(function($) {
    $('.delete-link').on('click', function() {
        var getLink = $(this).attr('href');
        swal({
            title: 'Alert',
            text: 'Delete?',
            html: true,
            confirmButtonColor: '#d9534f',
            showCancelButton: true,
        }, function() {
            // window.location.href = getLink // no redirection or page reload
            $.ajax({
                url: getLink, // link where your href is
                success: function(result) {
                    swal('Successful!!', 'Successfully deleted!!');  //sweet alert
                }
            });
        });
        return false;
    });
});