如何解决重定向到ASP .NET MVC中的页面后显示通知
下面是我的Ajax代码:
$.ajax({
url: '@Url.Action("AddUser","ControllerName")',dataType: 'json',contentType: 'application/x-www-form-urlencoded; charset=utf-8',type: 'POST',data: {
//data
},success: function (data,textStatus,jqXHR) {
console.log(jqXHR.status);
if (data.isSuccess) {
alert(data.message);
}
else {
alert(data.message);
}
window.location.href = "@Url.Action("Index","ControllerName")";
},error: function (jqXHR,errorThrown) {
console.log(jqXHR.status);
window.location.href = "@Url.Action("Index","ControllerName")";
}
});
我不想显示alert(data.message);
,而是希望在页面加载后显示自定义通知。
我不想传递任何查询字符串参数,因为它在url中可见。
1)
$(".notificationdiv").html("<div class='notification alert alert-success' role='alert'>
<strong> Operation performed successfully</strong>
</div>");
$(".notification").fadeOut(4000);
解决方法
在ajax成功之前,在window.location.href之前添加
sessionStorage.successMessage= true;
并将其添加到您的jquery中
$(function () {
if (sessionStorage.successMessage) {
$(".notificationdiv").html("<div class='notification alert alert-success' role='alert'><strong> Operation performed successfully</strong></div>");
$(".notification").fadeOut(4000);
sessionStorage.successMessage= false;
sessionStorage.removeItem("successMessage") //if you want remove from session storage
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。