我正在使用 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对象
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/