Hello I have a code using sweetalert
swal("Good job!", "You clicked the button!", "success")
this code will pop-up a message and has a button okay, what I like to do is I want to refresh the page after I click the okay button.
Can I do that?
Hello I have a code using sweetalert
swal("Good job!", "You clicked the button!", "success")
this code will pop-up a message and has a button okay, what I like to do is I want to refresh the page after I click the okay button.
Can I do that?
You can try this, it works for me.
swal({
title: "Good job",
text: "You clicked the button!",
type: "success"
},
function(){
location.reload();
}
);
The answer from Yoshioka did not work for me, I did this and it worked perfectly:
swal({title: "Good job", text: "You clicked the button!", type:
"success"}).then(function(){
location.reload();
}
);
Use the callback function...
Swal.fire({
// Swal Setting's
}).then((result) => {
// Reload the Page
location.reload();
});
For Sweet Alert 2, this will work.
swal("Good job!", "You clicked the button!", "success").then(function(){
location.reload();
});
As you can see migration guide
Sweet Alert 2 uses Promise
You can check confirm by this:
swal({
title: "Good job",
text: "You clicked the button!",
icon: "success",
buttons: [
'NO',
'YES'
],
}).then(function(isConfirm) {
if (isConfirm) {
location.reload();
} else {
//if no clicked => do something else
}
});
I use sweet alert 2 and this works for me
swal("Good job!", "You clicked the button!","success").then( () => {
location.href = 'somepage.html'
})
‘’’ The answers making use of location.reload() is going to trigger your form to attempt to resubmit over and over again, thats why you should use location.href instead.
In Sweet Alert 2, there is callback function where you can implement your logic :
Swal.fire({
title: 'Great job',
text: "You clicked the button!",
type: 'success',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if(result){
// Do Stuff here for success
location.reload();
}else{
// something other stuff
}
})
You can find the reference on SweetAlert2.
Swal.fire(
{
title: "Good job",
text: "You clicked the button!",
type: "success",
showDenyButton: true, // In case you want two scenarios
denyButtonText: 'ABC',
showCancelButton: true, // In case you want two scenarios
cancelButtonText:'XYZ'
}
).then(function (result) {
if (result.isConfirmed) {
//You can add code here if user pressed ok button
} else if (result.isDenied) {
//You can add code here if user pressed deny button
} else if(result.isDismissed) {
//You can add code here if user pressed cancel button
}
)
this worked for me.
Swal.fire('Deleted !!', data.message, 'success').then(() => {
location.reload();
});
swal({
title: "Process Completed",
text: "Data Recorded successfully",
buttons: true
}).then(function(){
location.reload();
});
i solved it with this :
swal({title: "Updated!", text: "yourText", type: "success"},function() {
location.reload();
}) // swal end
Another way :
swal("Updated!","yourText","success",function() {
location.reload();
}) // swal end