Posted By: Anonymous
After logging in via
$.ajax() to a site, I am trying to send a second
$.ajax() request to that site – but when I check the headers sent using FireBug, there is no session cookie being included in the request.
What am I doing wrong?
AJAX calls only send Cookies if the url you’re calling is on the same domain as your calling script.
This may be a Cross Domain Problem.
Maybe you tried to call a url from
www.domain-a.com while your calling script was on
www.domain-b.com (In other words: You made a Cross Domain Call in which case the browser won’t sent any cookies to protect your privacy).
In this case your options are:
- Write a small proxy which resides on domain-b and forwards your requests to domain-a. Your browser will allow you to call the proxy because it’s on the same server as the calling script.
This proxy then can be configured by you to accept a cookie name and value parameter which it can send to domain-a. But for this to work you need to know the cookie’s name and value your server on domain-a wants for authentication.
- If you’re fetching JSON objects try to use a JSONP request instead. jQuery supports these. But you need to alter your service on domain-a so that it returns valid JSONP responds.
Glad if that helped even a little bit.