Sweetalert: Redirect after pressing OK , in the Confirm alert.

Created on 23 Mar 2015  Â·  8Comments  Â·  Source: t4t5/sweetalert

Hello all. I been using the confirm alert.

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()
{   
swal("Deleted!", "Your imaginary file has been deleted.", "success"); });

Can I redirect/reload page after the user click OK on ("Deleted!", "Your imaginary file has been deleted.", "success") ?

Most helpful comment

@t4t5 Hey thanks for SweetAlert :) I found the solution for this issue and sharing it below.
I know its old but i found the solution so i hope it helps anyone.

@mp3il @azlannohara @masteradhoc The problem is the shorthand in the closure. You can do the required(Reload after clicking on "Okay" that appears after successful deletion) by using the below code:

   `$('a.delete-member').click(function() {
    var memberId = $(this).attr("data-member-id");
    deleteMember(memberId);
  });

  function deleteMember(memberId) {
    swal({
      title: "Are you sure?", 
      text: "Are you sure that you want to delete this member?", 
      type: "warning",
      showCancelButton: true,
      showLoaderOnConfirm: true,
      closeOnConfirm: false,
      confirmButtonText: "Yes, delete it!",
      confirmButtonColor: "#ec6c62"
    }, function() {
      $.ajax({
        url:  "/members/" + memberId + "/archive",
        type: "POST"
      })
      .done(function(data) {
        swal({
            title: "Deleted", 
            text: "Member has been successfully deleted", 
            type: "success"
        },function() {
            location.reload();
        });
      })
      .error(function(data) {
        swal("Oops", "We couldn't connect to the server!", "error");
      });
    });
  }`

All 8 comments

Maybe this could help you..
Follow an external link at https://www.ludu.co/lesson/how-to-use-sweetalert

Alright. Thanks!

On Wed, Mar 25, 2015 at 4:36 PM, Brian [email protected] wrote:

Maybe this could help you..
Follow an external link at
https://www.ludu.co/lesson/how-to-use-sweetalert

—
Reply to this email directly or view it on GitHub
https://github.com/t4t5/sweetalert/issues/319#issuecomment-85924369.

Passing another callback to the second swal seems to be a problem. have you found a solution?

I'll close this since it's not an issue.

@t4t5 - Can the second swal function confirm have a callback function? doesn't seem to work to me.

@t4t5 Hey thanks for SweetAlert :) I found the solution for this issue and sharing it below.
I know its old but i found the solution so i hope it helps anyone.

@mp3il @azlannohara @masteradhoc The problem is the shorthand in the closure. You can do the required(Reload after clicking on "Okay" that appears after successful deletion) by using the below code:

   `$('a.delete-member').click(function() {
    var memberId = $(this).attr("data-member-id");
    deleteMember(memberId);
  });

  function deleteMember(memberId) {
    swal({
      title: "Are you sure?", 
      text: "Are you sure that you want to delete this member?", 
      type: "warning",
      showCancelButton: true,
      showLoaderOnConfirm: true,
      closeOnConfirm: false,
      confirmButtonText: "Yes, delete it!",
      confirmButtonColor: "#ec6c62"
    }, function() {
      $.ajax({
        url:  "/members/" + memberId + "/archive",
        type: "POST"
      })
      .done(function(data) {
        swal({
            title: "Deleted", 
            text: "Member has been successfully deleted", 
            type: "success"
        },function() {
            location.reload();
        });
      })
      .error(function(data) {
        swal("Oops", "We couldn't connect to the server!", "error");
      });
    });
  }`

I used this code but Show error
VM1355:23 POST http://localhost:7100/Forces/Delete/5 500 (Internal Server Error)

function Delete(id) {
swal({
title: "Are you sure?",
text: "Are you sure that you want to delete this member?",
type: "warning",
showCancelButton: true,
showLoaderOnConfirm: true,
closeOnConfirm: false,
confirmButtonText: "Yes, delete it!",
confirmButtonColor: "#ec6c62"
}, function() {
$.ajax({
url: "/Forces/Delete/"+id,
type: "POST"
})
.done(function(data) {
swal({
title: "Deleted",
text: "Member has been successfully deleted",
type: "success"
},function() {
location.reload();
});
})
.error(function(data) {
swal("Oops", "We couldn't connect to the server!", "error");
});
});
}

@introwit it's working and grate. thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

voviks21 picture voviks21  Â·  9Comments

stefanoschrs picture stefanoschrs  Â·  9Comments

killernova picture killernova  Â·  11Comments

gabyrusu picture gabyrusu  Â·  9Comments

daybaryour picture daybaryour  Â·  13Comments