首页 > 利用ajax post表单,返回response设置cookie失效,该怎么办?

利用ajax post表单,返回response设置cookie失效,该怎么办?

实验了多次,返回的response中有Set-Cookie,但是返回主页刷新任然没有cookie。
下面是提交请求代码:

javascript$.post("/api/register",{
            name : name,
            email : email,
            passwd : CryptoJS.SHA1(email + ':' + password).toString(),
        },function(data, textStatus, xhr){
          if(data === "success create"){
            location.assign('/');
          }else{
            showError(data);
          }     
        });

问题找到了,是我设置cookie时没有设置path导致浏览器拒绝储存cookie。


你说的是node.js服务端设置的还是?

res.cookie(config.auth_cookie_name, auth_token,
    {path: '/', maxAge: 1000 * 60 * 60 * 24 * 30, signed: true, httpOnly: true}); 
    //cookie 有效期30天
【热门文章】
【热门文章】