首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在删除函数php中显示SweetAlert

在删除函数php中显示SweetAlert
EN

Stack Overflow用户
提问于 2019-03-20 11:16:39
回答 2查看 111关注 0票数 0

我试图在我的删除功能中显示甜蜜的提醒,但不幸的是,我的代码现在不能工作了,我已经搜索了类似的功能,我看到了一些,但它对我的想法没有帮助。以下是我的代码

代码语言:javascript
运行
复制
 <a id="<?php echo $id;?>" value="<?php echo $id;?>"  name="delete"   onclick="archiveFunction(this.id)">
                        <i class="glyphicon glyphicon-trash text-red"></i></a>

这是我的ajax请求

代码语言:javascript
运行
复制
 $(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();   
});
$('#reloadpage').click(function() {

    location.reload(true);
});
function archiveFunction(id) {
event.preventDefault(); // prevent form submit
var form = event.target.form; // storing the form
        swal({
  title: "Are you sure?",
  text: "But you will still be able to retrieve this file.",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, Delete it!",
  cancelButtonText: "No, cancel please!",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm){
  if (isConfirm) {
    // this is `post` request to the server
    // so you can get the data from $_POST variables, says $_POST['delete'] $_POST['v_id']
    $.ajax({
        method: 'POST',
        data: {'delete': true, 'id' : id },
        url: 'user_del.php',
        success: function(data) {

        }
    });
    swal("Updated!", "Your imaginary file has been Deleted.", "success");

} else {
    swal("Cancelled", "Your file is safe :)", "error");
}

这是我的档案查询。不用担心我的查询,我将状态设置为0,以便存档一个数据,它将转到存档页面。我只想在删除或归档数据时显示甜蜜警报。提前谢谢。

代码语言:javascript
运行
复制
 <?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index');
endif;
include("../dist/includes/dbcon.php");
$id=$_REQUEST['id'];
$result=mysqli_query($con,"UPDATE accounts_at SET status = 0 WHERE id ='$id'")
    or die(mysqli_error());
        if ($result !== false) {
 echo "<script type='text/javascript'>alert('Successfully deleted a account!');</script>";
    echo "<script>document.location='index'</script>";
    }

?>
EN

Stack Overflow用户

发布于 2019-03-20 12:40:48

试试这个:

代码语言:javascript
运行
复制
function archiveFunction(id) {
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        closeOnConfirm: false
    }, function (isConfirm) {
        if (!isConfirm) return;
        $.ajax({
            url: "delete.php",
            type: "POST",
            data: {
                id: id
            },
            dataType: "html",
            success: function () {
                swal("Done!", "It was succesfully deleted!", "success");
            },
            error: function (xhr, ajaxOptions, thrownError) {
                swal("Error deleting!", "Please try again", "error");
            }
        });
    });
}
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55253055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档