-4

I have a button where when user press, it shows yes or cancel if yes is pressed it redirects user to a url here is the code i am using

if (result.error == 2)
{
  if (confirm(result.message))
  {
    location.href = '/user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec; //
  }
}

Now i have installed Sweet alert 2 and i want to use it to confirm or cancel

John Snow
  • 11
  • 6
  • You must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – tgogos May 22 '17 at 13:43
  • 1
    Here's the [documentation](https://limonte.github.io/sweetalert2/) for SweetAlert2; you'll be most interested in the seventh example from the top. – Chris Forrence May 22 '17 at 13:45

2 Answers2

0

From your question i think now you have added Sweet Alert 2 Plugin.you want to change code for that

     swal({
  title: 'Are you sure?',
  text: "You will be redirected!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes'
},function(isConfirm){
  if (isConfirm) {
    window.location.href = "http://stackoverflow.com";
  }
  });
Gkrish
  • 1,591
  • 1
  • 11
  • 18
0

I have used this code and its working fine now

if (result.error == 2)
{
swal({
title: 'Are you sure?',
text: "Do you want to go to the Log In page?",
type: 'success',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, send me there!'
}, function(){
window.location.href = '/user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
});
}
John Snow
  • 11
  • 6