SweetAlert 并在条件正常和成功消息后重定向
SweetAlert and redirect if a condition is okay and after success message
我正在使用 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 数据 == "Followup",我需要重定向用户:
- 显示成功消息后
和
- 用户单击“确定”按钮后。
这怎么可能??我是新手,正在努力学习。
提前致谢..
您可以像这样将回调函数传递给swal object
swal({
title: "Report Saved",
type: "success",
text: "The user details saved successfully!",
confirmButtonColor: "#00B4B4"
},function() {
if(condition){
window.location = "redirectURL";
}
});
$.ajax({
type: "POST",
url: "test.php",
data: {name1:name,status1:status},
cache: false,
success: function(result){
$('#submit').prop('disabled', true);
swal({
title: "Success!",
text: "Please click yes to reload or relocate to the other page.",
type: "success",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
}).then((result) => {
if(result.value){
//this is your success swal, after clicking the yes button, it will reload or go to the other page.
location.reload(); // this is your location reload.
window.location.href='somepage.html'; // this is your relocate to other page.
}
})
},
error: function(result) {
swal({
title: "Save failed",
type: "warning",
text: "We are unable to save data due to technical reasons!",
confirmButtonColor: "#00B4B4"
});
}
});
顺便说一句,我使用 Sweetalert 2。
swal(
title: "Save failed",
type: "warning",
text: "We are unable to save data due to technical reasons!",
confirmButtonColor: "#00B4B4").then(() => { window.location = "redirectUrl" });
当您单击“确定”按钮时,您将被重定向到您的特定 URL。将“redirectUrl”替换为您想要的 URL
我正在使用 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 数据 == "Followup",我需要重定向用户:
- 显示成功消息后 和
- 用户单击“确定”按钮后。
这怎么可能??我是新手,正在努力学习。
提前致谢..
您可以像这样将回调函数传递给swal object
swal({
title: "Report Saved",
type: "success",
text: "The user details saved successfully!",
confirmButtonColor: "#00B4B4"
},function() {
if(condition){
window.location = "redirectURL";
}
});
$.ajax({
type: "POST",
url: "test.php",
data: {name1:name,status1:status},
cache: false,
success: function(result){
$('#submit').prop('disabled', true);
swal({
title: "Success!",
text: "Please click yes to reload or relocate to the other page.",
type: "success",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
}).then((result) => {
if(result.value){
//this is your success swal, after clicking the yes button, it will reload or go to the other page.
location.reload(); // this is your location reload.
window.location.href='somepage.html'; // this is your relocate to other page.
}
})
},
error: function(result) {
swal({
title: "Save failed",
type: "warning",
text: "We are unable to save data due to technical reasons!",
confirmButtonColor: "#00B4B4"
});
}
});
顺便说一句,我使用 Sweetalert 2。
swal(
title: "Save failed",
type: "warning",
text: "We are unable to save data due to technical reasons!",
confirmButtonColor: "#00B4B4").then(() => { window.location = "redirectUrl" });
当您单击“确定”按钮时,您将被重定向到您的特定 URL。将“redirectUrl”替换为您想要的 URL