javascript - 使用 javascript 的会话
问题描述
如何在不刷新页面的情况下管理会话?
描述:我在 First.aspx 页面上有一个模型弹出窗口,当单击 First.aspx 中的按钮时,使用 iframe 在弹出窗口中打开 Second.aspx 页面我想从Second.aspx
(服务器端)获取值,并在弹出窗口关闭而不重新加载时session["Value"]
显示在页面上First.aspx
这 First.aspx
可能吗?
我试过这样 - 但是这个会话值在重新加载 First.aspx 后显示
.cs 代码 (First.aspx)
Session["ComplaintValue"] = hfPresentComplaint.Value.Replace("'", "''");
Javascript 代码 ()
<script>
function closepopupsession() {
debugger;
var a = ' <%=Session["ComplaintValue"]%>'
if (a != null) {
var hidnvalComplaint = document.getElementById("hidnvalueComplaint").value
console.log(replaced);
}
}
</script>
解决方案
有不同的技巧可以做到这一点,但在我的情况下,我使用 Ajax 每 1 秒调用一次单独的页面,我在那里有我的会话,并且索引页面中有一个空的 div,如下所示:
function RefreshSessions()
{
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if(req.readyState == 4 && req.status == 200)
{
document.getElementById('EmptyDiv').innerHTML = req.responseText;
}
}
req.open('GET', 'update_sessions.php', true);
req.send();
}
setInterval(function(){RefreshSessions()}, 1000);
希望它会有所帮助。
推荐阅读
- python - 使用 sklearn 对我的数据集的一列进行二值化后,结果不正确。代码哪里错了?
- wordpress - 使用 Wordpress 和 Ionic 同步数据以供离线使用
- sql - SQL GROUP BY 语句 csv 导出显示不正确的总和
- mysql - 如何将姓名号码电子邮件ID添加到我的mysql数据库
- amazon-web-services - 来自自定义资源的云形成函数
- android - 如何使用 Firebase 17.0.1 执行 INSTANCE_ID_EVENT 操作?
- html - 无法平均显示 html 表格大小
- r - 如何计算R中一列中两个日期之间的天数
- javascript - Laravel 5 通过 laravel:5 查询检查表中是否存在两条记录
- r - 在R中查找数据框中的第二高值