[Answered ]-Ajax post data don't arrive to Django

1👍

The header for XMLHttpRequest is case sensitive. X-Requested-With

def add_new_question_feedback(request, pk):
    if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
        question = Question.objects.get(id=pk)
        feedback = QuestionFeedback(
        question=question, user=request.user, text=request.POST.get('feedback'), feedback_choice=request.POST.get('feedback_choice'))
        feedback.save()
        feedback = serializers.serialize('json', [feedback])
        return HttpResponse(feedback, content_type='application/json')

Leave a comment