为什么 SweetAlert 没有以正确的格式出现?
Why is SweetAlert not appearing in the correct format?
下面是我的 AJAX 调用之一的代码。当它进入 else
条件时,SweetAlert 代码不会以该代码格式触发。我不知道为什么。当我改用这段代码时,它工作正常:
swal("Task is still in progress", "Wait for status change to Done", "warning");
因为我想在单击 swal 上的“确定”时重定向到一个页面,所以我无法使用此代码。
可能是什么原因?
if (placeholder4Status == 'Done') {
$.ajax({
type: "GET",
url: "/addTasks-approve",
dataType: "json",
data: {
text: text,
id: id
},
contentType: "application/json",
success: function(response) {
if (response.status == '200') {
window.location.replace('/tasksAdmin');
$.LoadingOverlay("hide");
}
}
});
} else {
$.LoadingOverlay("hide");
// swal("Task is still in progress", "Wait for status change to Done ", "warning");
swal({
title: "Task is still in progress!",
text: "Please wait for status change to Done ",
type: "warning",
showCancelButton: true
}, function() {
window.location.href = '/tasksAdmin';
// window.location.replace('/tasksAdmin');
});
return false;
}
你把执行window.location.href
的函数放的不太对。相反,您可以尝试使用 Promises 更改您的代码,这是一个示例:
swal({
title: "Task is still in progress!",
text: "Please wait for status change to Done ",
type: "warning",
showCancelButton: true
}).then((result) => {
if (result) {
window.location.href = '/tasksAdmin';
}
});
下面是我的 AJAX 调用之一的代码。当它进入 else
条件时,SweetAlert 代码不会以该代码格式触发。我不知道为什么。当我改用这段代码时,它工作正常:
swal("Task is still in progress", "Wait for status change to Done", "warning");
因为我想在单击 swal 上的“确定”时重定向到一个页面,所以我无法使用此代码。 可能是什么原因?
if (placeholder4Status == 'Done') {
$.ajax({
type: "GET",
url: "/addTasks-approve",
dataType: "json",
data: {
text: text,
id: id
},
contentType: "application/json",
success: function(response) {
if (response.status == '200') {
window.location.replace('/tasksAdmin');
$.LoadingOverlay("hide");
}
}
});
} else {
$.LoadingOverlay("hide");
// swal("Task is still in progress", "Wait for status change to Done ", "warning");
swal({
title: "Task is still in progress!",
text: "Please wait for status change to Done ",
type: "warning",
showCancelButton: true
}, function() {
window.location.href = '/tasksAdmin';
// window.location.replace('/tasksAdmin');
});
return false;
}
你把执行window.location.href
的函数放的不太对。相反,您可以尝试使用 Promises 更改您的代码,这是一个示例:
swal({
title: "Task is still in progress!",
text: "Please wait for status change to Done ",
type: "warning",
showCancelButton: true
}).then((result) => {
if (result) {
window.location.href = '/tasksAdmin';
}
});