最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery Sweet Alert Unexpected 2nd argument error - Stack Overflow

programmeradmin3浏览0评论

I am using sweet alert plugin and getting an error. I have tried every example but can't understand what this error means

Uncaught SweetAlert: Unexpected 2nd argument (function() { setTimeout(function() {ckquote

My code:

<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 ments 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>

My whole error on console window:

sweetalert.min.js:1 Uncaught SweetAlert: Unexpected 2nd argument (function() {
 setTimeout(function() {
 $.post("../delete.php", {
 id: postID
 },
 function(data) {
 swal({
 title: "Deleted!",
 text: "Your post has been deleted.",
 type: "success"
 },
 );
 }
 );

 }, 50);
 })

I am using sweet alert plugin and getting an error. I have tried every example but can't understand what this error means

Uncaught SweetAlert: Unexpected 2nd argument (function() { setTimeout(function() {ckquote

My code:

<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 ments 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>

My whole error on console window:

sweetalert.min.js:1 Uncaught SweetAlert: Unexpected 2nd argument (function() {
 setTimeout(function() {
 $.post("../delete.php", {
 id: postID
 },
 function(data) {
 swal({
 title: "Deleted!",
 text: "Your post has been deleted.",
 type: "success"
 },
 );
 }
 );

 }, 50);
 })
Share Improve this question edited Apr 20, 2018 at 22:59 sach jot asked Apr 20, 2018 at 22:52 sach jotsach jot 5704 silver badges18 bronze badges 2
  • 1 it looks like sweet alert doesn't take a second argument, so passing in ` function() { location.reload(); }` as the second argument isn't allowed, and they programmed it to actually let you know. – dave Commented Apr 20, 2018 at 22:56
  • @dave I removed the reload function but still go the above error – sach jot Commented Apr 20, 2018 at 23:00
Add a ment  | 

1 Answer 1

Reset to default 4

Sweet Alert can be invoked in two ways

  • 1, 2, or 3 strings parameters

    swal(["title",] "text" [, "iconname"])
    
  • a single object parameter containing all the options:

    swal({
        title: "Are you sure?",
        text: "If you delete this post all associated ments also deleted permanently.",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        showLoaderOnConfirm: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Yes, delete it!",
    });
    

If you want to do something with the response, it returns a promise, and you can retrieve the value with .then:

swal({
  title: "Are you sure?",
  text: "If you delete this post all associated ments 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);
});
发布评论

评论列表(0)

  1. 暂无评论