Commits

Rafael A  committed 31f6779

AJAX improvements: GET - > POST

  • Participants
  • Parent commits 65a8bb1

Comments (0)

Files changed (3)

     'django.core.context_processors.i18n',
     'django.core.context_processors.request',
     'django.core.context_processors.static',
+    'django.middleware.csrf.CsrfViewMiddleware',
 ) 
 
 

File poll/ajax.py

                     return HttpResponse('Non-authenticated users can\'t vote',
                                         status=400)
 
-            chosen_items = simplejson.loads(request.GET['chosen_items'])
+            chosen_items = simplejson.loads(request.POST['chosen_items'])
         except:
             return HttpResponse('Wrong parameters', status=400)
 

File poll/templates/_polls_script.js

 	});
 	
 	function doResults() {
-		$.get(result_url, function(data) {
+		$.post(result_url, {'csrfmiddlewaretoken': '{{ csrf_token }}'}, function(data) {
 			showResults($.parseJSON(data));
 		});
 	}
 				return;
 			}
 			body.hide('slow', complete=function() {
-				$.get(vote_url, {'chosen_items': result}, function() {
+				$.post(vote_url, {'chosen_items': result, 'csrfmiddlewaretoken': '{{ csrf_token }}'}, function() {
 					doResults();
 				});
 			});