Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery甜警报意外的第二个参数错误_Javascript_Jquery_Sweetalert - Fatal编程技术网

Javascript jQuery甜警报意外的第二个参数错误

Javascript jQuery甜警报意外的第二个参数错误,javascript,jquery,sweetalert,Javascript,Jquery,Sweetalert,我正在使用sweet alert插件,但出现了一个错误。我已经尝试了每一个例子,但不明白这个错误意味着什么 未捕获的SweetAlert:意外的第二个参数(函数(){ setTimeout(函数(){ckquote 我的代码: <script type="text/javascript"> $('.delete-confirm').on('click', function() { var postID = $(this).val(); console.log(post

我正在使用sweet alert插件,但出现了一个错误。我已经尝试了每一个例子,但不明白这个错误意味着什么

未捕获的SweetAlert:意外的第二个参数(函数(){ setTimeout(函数(){ckquote

我的代码:

<script type="text/javascript">
$('.delete-confirm').on('click', function() {
    var postID = $(this).val();
    console.log(postID);
    swal({
        title: "Are you sure?",
        text: "If you delete this post all associated comments also deleted permanently.",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        showLoaderOnConfirm: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Yes, delete it!",
    }, function() {
        setTimeout(function() {
            $.post("../delete.php", {
                    id: postID
                },
                function(data) {
                    swal({
                            title: "Deleted!",
                            text: "Your post has been deleted.",
                            type: "success"
                        },
                    );
                }
            );

        }, 50);
    });
});
</script>

可以通过两种方式调用Sweet Alert

  • 1、2或3个字符串参数

    swal(["title",] "text" [, "iconname"])
    
  • 包含所有选项的单个对象参数:

    swal({
        title: "Are you sure?",
        text: "If you delete this post all associated comments also deleted permanently.",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        showLoaderOnConfirm: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Yes, delete it!",
    });
    
如果要对响应执行某些操作,它将返回一个承诺,您可以使用
检索该值。然后

swal({
  title: "Are you sure?",
  text: "If you delete this post all associated comments also deleted permanently.",
  type: "warning",
  showCancelButton: true,
  closeOnConfirm: false,
  showLoaderOnConfirm: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
}).then(function() {
  setTimeout(function() {
    $.post("../delete.php", {
        id: postID
      },
      function(data) {
        swal({
          title: "Deleted!",
          text: "Your post has been deleted.",
          type: "success"
        }, );
      }
    );

  }, 50);
});

看起来sweet alert不接受第二个参数,因此传入'function(){location.reload();}`因为第二个参数是不允许的,他们对它进行了编程,让您知道。@dave我删除了重新加载函数,但仍然出现上述错误非常感谢,我现在理解了这个概念。非常感谢
swal({
  title: "Are you sure?",
  text: "If you delete this post all associated comments also deleted permanently.",
  type: "warning",
  showCancelButton: true,
  closeOnConfirm: false,
  showLoaderOnConfirm: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
}).then(function() {
  setTimeout(function() {
    $.post("../delete.php", {
        id: postID
      },
      function(data) {
        swal({
          title: "Deleted!",
          text: "Your post has been deleted.",
          type: "success"
        }, );
      }
    );

  }, 50);
});