【发布时间】:2015-07-11 01:25:58
【问题描述】:
我需要在 JQuery 中获取响应会话 cookie。我需要知道会话是否已过期,我相信唯一的方法是检查来自服务器的响应是否包含会话 cookie 我在后端使用播放框架,它不会在后端保留会话详细信息,并且仅将会话详细信息保留在 cookie 中
我试图从这样的响应中获取 cookie -
$.ajax({type:'POST', url: '@@{search()}', data:$('#searchForm').serialize(),
success: function(data, testStatus, jqXHR) {
if (data.indexOf("errorsSection") > 0) {
alert("trying to get access of cookies from response header in if :"+ jqXHR.getResponseHeader("PLAY_SESSION"));
$('#searchResults').hide();
$('#errors').html(data);
$('#errors').show();
} else {
alert("trying to get access of cookies from response header in else :"+ jqXHR.getResponseHeader("PLAY_SESSION"));
alert("trying to get access of cookies from response header in else :"+ jqXHR.getAllResponseHeaders());
alert("in else::::" + $.cookie("PLAY_SESSION") );
$('#errors').hide();
$('#searchResults').html(data);
$('#searchResults').show();}
jqXHR.getResponseHeader("PLAY_SESSION") 返回 null 而 jqXHR.getAllResponseHeaders() 提供除 cookie 数据之外的所有标头特定数据。
你能帮我从响应中找到 cookie 吗?
非常感谢您的帮助。
谢谢, 莫希特
【问题讨论】:
-
如何设置cookie?
标签: javascript jquery cookies playframework-2.0 session-cookies