xhr(ajax)请求不发送所有cookie(nodeJS)

时间:2016-01-13 11:34:40

标签: node.js http-headers session-cookies setcookie

使用nodeJS我成功设置了一个cookie。

enter image description here

当我呼叫一个页面时,我正在发出2个请求。

一个用于初始页面,一个是DOM加载后的ajax请求

http://domain.com/pages/blog

http://domain.com/dataRequest

我的cookie出现在节点服务器上的初始请求中

http://domain.com/pages/blog

b_switch_session_id=3442047e6f50effc9108709bae089aa4;  
_shopify_y=F8DD2A56-4D75-4478-ACF4; 
_shopify_y=F8DD2A56-4D75-4478-ACF4;
ajs_anonymous_id=%2258922eb3-abd1-44a6-a35b-4dbe00bf62ba%22; 
_session_id=40ac642b90ec66f0da1b0f6af9176f7d;  
_shopify_visit=t; 
_shopify_uniq=x; 
_shopify_s=8B5A83C5-3B48-4EF7-816A;
_shopify_s=8B5A83C5-3B48-4EF7-816A;
ajs_group_id=null; 
ajs_user_id=null;
_ga=GA1.2.1751239978.1452678921; 
_gat=1

但不是在ajax请求中

    ajs_anonymous_id=%2258922eb3-abd1-44a6-a35b-4dbe00bf62ba%22; 
    _session_id=40ac642b90ec66f0da1b0f6af9176f7d; 
    _shopify_y=F8DD2A56-4D75-4478-ACF4; 
    _ga=GA1.2.1751239978.1452678921; 
    _gat=1; 
    _shopify_visit=t; 
    _shopify_uniq=x; 
    _shopify_s=8B5A83C5-3B48-4EF7-816A; 
    ajs_group_id=null; 
    ajs_user_id=null

注意:由于某种原因,shopify会设置重复的Cookie。这些重复的cookie出现在节点上的request.headers中,用于初始请求,但是重复项确实出现在节点中,用于ajax请求

function callAjax(Url) 
    {  
       //get domain name from url
        var url = Url
        var arr = url.split("/");
        var domain = arr[0] + "//" + arr[2]
        var ref = window.location.href;
         //console.log(ref);

        var xmlhttp;

        if (window.XMLHttpRequest) 
        {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function() 
        {

        }

        xmlhttp.open("GET", domain+"/dataRequest", true);
        xmlhttp.send(ref);
    }

1 个答案:

答案 0 :(得分:0)

我明白了。

Cookie正在为特定页面/博客的路径设置自己

修正:

{'set-cookie':'b_switch_session_id=lsd34JF3krK; path=/'}