This is the code of my ajax function: <script type="text/javascript"> $(document).ready(function() { $('#vote_form').submit(function(event) { event.preventDefault(); var data = { project: {{ project.id }}, user: {{ user.id }} }; $.ajax({ type: 'POST', url: {% url vote %}, data: data, success: function(responseData) { //$('#vote_button').disabled = true; alert('Hey!'); }, dataType: "json" }); }); }); </script>
This is the code of html: <div class="vote"> <form id="vote_form" method="post"> <input type="submit" id="vote_button" value="{% trans "Vote" %}" class="submit"> <!--<input type="hidden" name="project" value="{{ project.id }}" /> <input type="hidden" name="user" value="{{ user.id }}" />--> {% csrf_token %} </form> </div> This is from urls.py: url(r'^vote/$', views.vote_handler, name="vote"), This is from views.py: #...@login_required def vote_handler(request): if (request.method == 'POST'): data = request.POST.get('data', None) if request.is_ajax() and data: project_id = data.project user_id = data.user return HttpResponse("{'response_text': '" + project_id + " recieved.'}", mimetype="application/json") else: return HttpResponse("{'response_text': 'error recieved.'}", mimetype="application/json") What is going wrong? When I press the Vote button, the form is submitted, but nothing happens. Kostia -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.