I have a Django site and I am trying to set a cookie in a response from an AJAX call. I made the question more general since nowbody was answering Cookies not working with an AJAX call from jQuery to Django
On the client side I have a JavaScript function sending a GET request to a URL:
$.ajax({
url: url,
success: function(data) {
alert('Load was performed.');
}
});
On the server side I have code setting the cookie:
def vote(request, slug, rating):
# Some irrelevant code...
response = HttpResponse('Vote changed.')
response.set_cookie('vote', 123456)
return response
I get the response in the jQuery code, but the problem is that the cookie is never set in the browser.
What I am doing wrong?
Thanks!