Does jQuery send cookies in a post?

前端 未结 5 1870
执念已碎
执念已碎 2020-12-09 07:42

I want to know if, when I make a $.post(...) with jQuery, is any cookie sent to the server in the post request?

Thanks!

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 08:38

    One thing to consider is cookie path. If an ajax-loaded script sets a cookie then its path may be different than the parent page, putting it in a different scope for some server applications or JQuery. I spent a while today spinning my wheels on this then noticed the cookies I was having trouble reading had a different path set.

    Simple fix for me was to set the path of all cookies to / with jquery in my ajax request like so:

     $.cookie("isolates_grid_tgl", "true", { path: "/" });
    

    firebug cookies view

提交回复
热议问题