Can an AJAX response set a cookie? If not, what is my alternative solution? Should I set it with Javascript or something similar?
Thanks,
Billy.
Can an AJAX response set a cookie? If not, what is my alternative solution? Should I set it with Javascript or something similar?
Thanks,
Billy.
Yes, you can set cookie in the AJAX request in the server-side code just as you'd do for a normal request since the server cannot differentiate between a normal request or an AJAX request.
AJAX requests are just a special way of requesting to server, the server will need to respond back as in any HTTP request. In the response of the request you can add cookies.
According to the w3 spec section 4.6.3 for XMLHttpRequest a user agent should honor the Set-Cookie header. So the answer is yes you should be able to.