Why is jquery's .ajax() method not sending my session cookie?

后端 未结 11 1659
长情又很酷
长情又很酷 2020-11-22 02:25

After logging in via $.ajax() to a site, I am trying to send a second $.ajax() request to that site - but when I check the headers sent using FireB

11条回答
  •  野的像风
    2020-11-22 03:10

    Just my 2 cents on setting PHPSESSID cookie issue when on localhost and under dev environment. I make the AJAX call to my REST API endpoint on the locahost. Say its address is mysite.localhost/api/member/login/ (virtal host on my dev environment).

    • When I do this request on Postman, things go fine and PHPSESSID is set with the response.

    • When I request this endpoint via AJAX from the Browsersync proxied page (e.g. from 122.133.1.110:3000/test/api/login.php in my browser address line, see the domain is different vs mysite.localhost) PHPSESSID does not appear among cookies.

    • When I make this request directly from the page on the same domain (i.e. mysite.localhost/test/api/login.php) PHPSESSID is set just fine.

    So this is a cross-origin origin request cookies issue as mentioned in @flu answer above

提交回复
热议问题