K
K
kicherov_maxim2019-03-13 09:26:04
Django
kicherov_maxim, 2019-03-13 09:26:04

How to submit multiple ajax forms and accept django?

Good afternoon, I'm doing a questionnaire, I have a lot of forms, I want to send them all with Ajax at a time. All forms have a .questionform class. I do it like this:

function finish(){
        var csrftoken = getCookie("csrftoken");
        results =$(".questionform").serialize();
        var formData = new FormData(results);

        $.ajaxSetup({
            beforeSend: function(xhr) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        });

        $.ajax({
            type: 'POST',
            url: '/validation',
            contentType: false,
            dataType: 'json',
            cache: false,
            processData: false,
            data: formData,
            success: function(data) {
                console.log(data);

            }
        });

    }

in django
def validation(request):
    print(request.POST)
    return HttpResponse("ok")

displays <QueryDict: {}>
Tell me how to do it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question