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

后端 未结 11 1529
长情又很酷
长情又很酷 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:22

    Adding my scenario and solution in case it helps someone else. I encountered similar case when using RESTful APIs. My Web server hosting HTML/Script/CSS files and Application Server exposing APIs were hosted on same domain. However the path was different.

    web server - mydomain/webpages/abc.html

    used abc.js which set cookie named mycookie

    app server - mydomain/webapis/servicename.

    to which api calls were made

    I was expecting the cookie in mydomain/webapis/servicename and tried reading it but it was not being sent. After reading comment from the answer, I checked in browser's development tool that mycookie's path was set to "/webpages" and hence not available in service call to

    mydomain/webapis/servicename

    So While setting cookie from jquery, this is what I did -

    $.cookie("mycookie","mayvalue",{**path:'/'**});
    

提交回复
热议问题