javascript - AJAX - Set-Cookie not working for same domain but different path -
the browser doesn't allow me this:
1) load http://localhost:8080/myapp/page1
-> sets jsessionid cookie path=/myapp , domain=localhost
2) through ajax request call http://localhost:3000/login?user=xxx
-> in response, both in chrome & firebug, see: set-cookie: connect.sid=xxxxxxyyyyyy path=/ domain=localhost
i expecting when performed ajax call, instance http://localhost:3000/anothercall
(still staying in http://localhost:8080/myapp/page1
), browser send cookie connect.sid in headers. however, doesn't!!
any idea why? both cookies belong same domain, difference path there shouldn't cross domain issues.
additionaly have tried setting headers in nodejs response. same result:
res.header('access-control-allow-origin', "*"); res.header('access-control-allow-methods', 'get,put,post,delete,options'); res.header('access-control-allow-headers', 'cookie, content-type, authorization, content-length, x-requested-with'); res.header('access-control-expose-headers', 'set-cookie, x-powered-by');
checking cookies info firebug , chrome dev tools seems if broweser weren't storing connect.sid cookie @ all. wonder if it's assuming domains different (one localhost:8080 , other localhost:3000...)
in case has same problem. got work:
adding additionally header
res.header('access-control-allow-credentials', 'true');
setting
xhrfields
in $.ajax call:xhrfields: { withcredentials: true }
now cookie added in browser , sent in subsequent requests.
Comments
Post a Comment