【发布时间】:2017-04-27 14:58:24
【问题描述】:
在我的 ajax 调用中,如果成功,我想重定向到另一个 URL 并显示由 toastr 形成的消息。
这是我的 ajax:
var redirectUrl = '@Url.Action("Index", "Informations")';
bootbox.confirm({
title: "Delete?",
message: "Are you sure you want to delete this?",
buttons: {
cancel: {
label: '<i class="fa fa-times"></i> Cancel'
},
confirm: {
label: '<i class="fa fa-check"></i> Confirm'
}
},
callback: function(result) {
if (result) {
toastr.options = {
timeOut: 5000
}
$.ajax({
url: "/api/Informations/" + btn.attr("data-id"),
method: "DELETE",
success: function () {
window.location.href = redirectUrl;
toastr.success("Successfully deleted");
},
error: function(jqXHR, textStatus, errorThrown) {
var status = capitalizeFirstLetter(textStatus);
toastr.error(status + " - " + errorThrown, "Sorry, something went wrong.");
}
});
}
}
});
现在问题肯定是调用 toastr.success 方法之前的重定向.. 那么如何在新页面上显示成功消息?
【问题讨论】: