Sweetalert: How can execute location.reload after I clicked the okay button?

Created on 30 Mar 2016  路  2Comments  路  Source: t4t5/sweetalert

function removed_confrm(id, company){
var the_url = "";
var view = "";
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() {
$.ajax({
type: "GET",
data: {
'company_id': id
},
url: the_url,
success: function(data) {
if (data == id) {
swal("Deleted!", "Your "+company+" has been deleted.", "success");
location.reload();
}
},
error: function(data) {
swal("We cannot delete!", "Your "+company+" file has not been deleted.", "error");
}
});
}
);
}

This case the sweetalert will exit and then the location.reload will execute, I would like to click the okay first the execute location.reload.

Most helpful comment

Hi,

Did you tried attaching a function to the confirm button as described in official website?

In your case I guess something like the following would do the trick:
swal({ title: "Deleted!", text: "Your "+company+" has been deleted.", type: "success" }, function(){ location.reload(); });

All 2 comments

Hi,

Did you tried attaching a function to the confirm button as described in official website?

In your case I guess something like the following would do the trick:
swal({ title: "Deleted!", text: "Your "+company+" has been deleted.", type: "success" }, function(){ location.reload(); });

Yes This works for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mateuszjarzewski picture mateuszjarzewski  路  4Comments

rafatux picture rafatux  路  5Comments

AlexV525 picture AlexV525  路  4Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  4Comments

krishnamraju picture krishnamraju  路  3Comments