我正在使用SweetAlert的版本1:

https://github.com/errakeshpd/sweetalert-1

我的示例ajax代码如下所示,其中保存了用户数据。

$.ajax({
type: "POST",
url: "test.php",
data: {name1:name,status1:status},
cache: false,
success: function(result){
$('#submit').prop('disabled', true);
swal({
title: "Report Saved",
type: "success",
text: "The user details saved successfully!",
confirmButtonColor: "#00B4B4"
  });
},//success
error: function(result)
{
swal({
title: "Save failed",
type: "warning",
text: "We are unable to save data due to technical reasons!",
confirmButtonColor: "#00B4B4"
   });
 }
});


如果status1 data ==“ Followup”,我需要重定向用户:


显示成功消息后

用户单击确定按钮后。


那怎么可能?我是新手,正在尝试学习。

预先感谢..

最佳答案

您可以像这样将回调函数传递给swal object

swal({
     title: "Report Saved",
     type: "success",
     text: "The user details saved successfully!",
       confirmButtonColor: "#00B4B4"
  },function() {
    if(condition){
       window.location = "redirectURL";
    }
  });

关于javascript - SweetAlert并重定向,如果条件还可以,并且在成功消息之后,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52676504/

10-11 07:49