Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Jquery中获取响应会话cookie_Javascript_Jquery_Cookies_Playframework 2.0_Session Cookies - Fatal编程技术网

Javascript 如何在Jquery中获取响应会话cookie

Javascript 如何在Jquery中获取响应会话cookie,javascript,jquery,cookies,playframework-2.0,session-cookies,Javascript,Jquery,Cookies,Playframework 2.0,Session Cookies,我需要在JQuery中获取响应会话cookie。我需要知道会话是否已过期,我认为唯一的方法是检查来自服务器的响应是否包含会话cookie 我在后端使用play框架,它不在后端保留会话细节,只在cookie中保留会话细节 我试图从这样的回答中得到cookie- $.ajax({type:'POST', url: '@@{search()}', data:$('#searchForm').serialize(), success: function(data, te

我需要在JQuery中获取响应会话cookie。我需要知道会话是否已过期,我认为唯一的方法是检查来自服务器的响应是否包含会话cookie 我在后端使用play框架,它不在后端保留会话细节,只在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吗

非常感谢你的帮助

谢谢,
Mohit

您不需要在前端检查cookie,实际上您不应该检查cookie,特别是如果您关心安全性的话

如果一切正常,您的后端操作应该返回结果

如果用户未被跟踪,则可以返回(
unhorized()
在Scala中)

而在jQuery中,您应该使用
success
error
回调来处理它们


编辑:刚刚回答了非常类似的问题:,实际上要获取标题,您需要先设置它们(cookie不是标题)

如何设置cookie?非常感谢您的建议。我会试试看。