Does jQuery send cookies in a post?

前端 未结 5 1865
执念已碎
执念已碎 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条回答
  •  离开以前
    2020-12-09 08:27

    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 :/

提交回复
热议问题