I want to know if, when I make a $.post(...) with jQuery, is any cookie sent to the server in the post request?
Thanks!
I want to know if, when I make a $.post(...) with jQuery, is any cookie sent to the server in the post request?
Thanks!
Cookies are sent with Ajax requests.
When the HTTPOnly flag is set for a cookie, this cookie is hidden from client-side scripts, but the cookie is still sent with Ajax requests.
Using the same cookies on the client and the server is not possible when you have httpOnlyCookies switched on. There is very good reason switch this on too:
Using Firefox+Firebug you can see exactly what jQuery sends, and how. Useful for debugging!
Sorry to be a wet blanket, but I'm going to contradict the positive vibes here and say NO.
I'm currently building an app using $.post to connect to my API backend, which is powered by Express and node.js. I'm using the Express cookie parser middleware to read cookies sent over in each request. If I hit my endpoint directly via the browser the backend server can see the cookies visible on my domain. However, when I use $.post in my app the cookie object is just blank.
It's possible I'm missing something but I've been testing this for the last couple hours and the conclusion I've come to is that cookies are simply not sent using a jQuery $.post request :/
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: "/" });