Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Cookie in Javascript then window.location.href doesn't send updated coookie

I'm setting a cookie using jquery.cookie. I can verify after setting that it's available in javascript with $.cookie("somecookie").

However when I do a window.location.href = "/somerelativeurl" the updated cookie is not sent to the server. (only the old version is sent.)

Since my code will do a redirect if the cookie isn't updated properly, I can also see the redirect request, and it has the cookie on it properly updated and everything.

What am I doing wrong?

like image 660
James Hancock Avatar asked Feb 17 '23 06:02

James Hancock


1 Answers

It's probably a path problem.

Try to set cookie as follow:

$.cookie("somecookie", 1, { path : "/" });
like image 125
Luca Rainone Avatar answered May 12 '23 02:05

Luca Rainone