c# - 注销后重定向用户
问题描述
我正在尝试制作一个注销系统,在 c# 中注销正常工作,但是在前端,当我单击注销按钮时,isLogged 变量在数据库中更改为 0 of 1(应该是)但在浏览器中用户未重定向到登录页面,我收到错误“请求的 JSON 解析失败”
我尝试让 ajax 调用正常工作,我在这个站点上搜索解决方案,但我无法解决这个问题
var userAIDI = window.localStorage.getItem('userId');
console.log(userAIDI)
var usr = {
userId:userAIDI
}
$.ajax({
type: "POST",
url: "https://localhost:44378/api/userLogOut",
data: JSON.stringify(usr),
contentType: "application/json",
dataType: "json",
success: function (data) {
window.location.href = "pages/login.html";
// Replace the div's content with the page method's return.
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
},
});
解决方案
问题可能与 .html 扩展名有关。
浏览器倾向于在浏览历史记录中保留 .html 的缓存更长时间。尝试在谷歌浏览器的隐身标签中测试该功能,或尝试将所有文件转换为 .asp 或 .php(无论您使用的是哪个)。
我建议这样做是因为您的代码看起来不错,并且数据库也可以正确反映,正如您在此处所建议的那样:
“ isLogged 变量在数据库中更改为 0 of 1(应该如此),但在浏览器中,用户不会被重定向到登录页面”。
推荐阅读
- dataframe - 如何在 pyspark 数据框中将时间戳转换为 bigint
- graph - 将图形编辑距离标准化为 [0,1] (networkx)
- c++ - 创建链表,但不能按 cpp 的预期工作
- python - 查找最后一个整数并返回变量名
- python - 我可以做出改变来避免 SVR 中的负 R2 分数吗?
- html - 使用 css 定位 fontawesome 图标
- c# - 如何将图像绑定到嵌套图像的网格具有不同绑定上下文的列表?
- python - Python列表如何再次从最后一个到第一个?
- node.js - db-migrate 从 csv 插入数据
- python - 程序返回 none 而不是 value