views:

35

answers:

1

I know when you request a page normally it is typically the case that you would use server side session data and set cookies via HTTP headers, but does it work the same when the content is requested via AJAX?

+2  A: 

An AJAX request contains the same request/response information as a traditional HTTP request. You can set cookies on the client once the async callback is executed, etc.

Cesar
@Cesar I'm sorry for being dumb but can you elaborate. Are you saying, yes you can set cookies using your web server's HTTP headers like normal even during JavaScript? Or, when you say "on the client", are you saying I should set them using the client (ie, JavaScript). I want to be able to set them from the server so I can use database sessions easily, but if I can't I guess it's not the end of the world.
orokusaki
Sorry for not being clear enough. The response you get from an async request made from JavaScript, is the same you would get if your request was not made via AJAX. In short, yes you can set cookies if your request was made with AJAX. It depends on the server side code to set response headers.
Cesar
@Cesar Awesome. Thanks!
orokusaki