With nodeJS i am successfully setting a cookie.
When i call a page, I am making 2 requests.
One for the initial page and an ajax request once the DOM has loaded
My cookie appears in the initial request on the node server
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
But not in the ajax request
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
Note: For some reason shopify sets duplicate cookies. These duplicate cookies appear in request.headers on node for the initial request, but the duplicates do note appear in node for the ajax request
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);
}
I figured it out.
The cookie was setting its self for the path of the specific page /blog
fix:
{'set-cookie':'b_switch_session_id=lsd34JF3krK; path=/'}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.