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
1 Answer
Reset to default 4Sweet 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);
});