HTTP Cookies and Ajax requests over HTTPS HTTP Cookies and Ajax requests over HTTPS ajax ajax

HTTP Cookies and Ajax requests over HTTPS


Ok, found the solution to the cookie problem.

See XHR specs, jQuery docs and StackOverflow.

The solution to have the cookies sent when switching protocol and/or subdomain is to set the withCredentials property to true.

E.g. (using jQuery)

 $.ajax( {   /* Setup the call */   xhrFields: {     withCredentials: true   } });


Document.cookie and Ajax Request does not share the cookie. Otherwise, ajax can't access the cookies from document.cookie or the response headers. They can only be controlled by the remote domain.

If you first get response including cookie from server by ajax, Since that you can request ajax communication with cookie to server.

For this case, you write such as below code (jQuery)

 $.ajax({      xhrFields : {           withCredentials : true      } });

See this article and demo