Cookies not working with AJAX call from jQuery to Django

I have a Django website using a 5-star rating system for voting (I use django ratings ), and I would like to keep users voting with AJAX calls.

On the client side, I have a JavaScript function that sends a GET request to the URL:

$.ajax({ url: url, success: function(data) { alert('Load was performed.'); } }); 

On the server side, I have the code setting the cookie:

 def vote(request, slug, rating): # Some irrelevant code... response = HttpResponse('Vote changed.') response.set_cookie('vote', 123456) return response 

The problem is that the cookie is never set in the browser.

What am I doing wrong?

Thanks!

0
source share
1 answer

Are you sure that your problem is related to the protection of fakes based on mutual access? Most ajax requests were rejected by django. You have no error messages?

0
source

Source: https://habr.com/ru/post/1385142/


All Articles