javascript - SweetAlert 并在条件正常和成功消息后重定向

标签 javascript jquery sweetalert

我正在使用 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",我需要重定向用户:

  1. 显示成功消息后 和
  2. 在用户点击确定按钮后。

这怎么可能??我是新手,正在努力学习。

提前致谢..

最佳答案

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

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/

相关文章:

javascript - 发出警报时,Sweet alert 2 未显示为模态

javascript - sweetalert JS 插件迁移到 Sweetalert2

javascript - 通过其父 ID 选择 ID

javascript - React-native - iOS 设备崩溃 "undefined is not an object (evaluating ' s.Manager')"

类中的 JavaScript 事件

ruby-on-rails - 带远程的 form_tag : true does not make an ajax request

javascript - jQuery 更改了 html 页面的内容,但 "View Source"不反射(reflect)更改

javascript - 我如何使用 JavaScript 将结果与其他文本一起使用

javascript - 将字符串与正则表达式匹配会给出 null,即使它应该匹配

javascript - 简单的主体加载功能不触发我的功能