S
S
s_stepashka2020-04-16 07:46:59
Django
s_stepashka, 2020-04-16 07:46:59

Why doesn't render fire in views.py django when passing ajax request?

On the html page there is an input and ajax to it, which passes some value to views.py

<input type="text" name="zayavka_number" required="" id="id_zayavka_number" placeholder="введите номер заявки для отображения" onchange="sortComplectTable(value)">
<script> function sortComplectTable(value) {
    $.ajax({
                url: "/sort_complect_table",
                type: "POST",
                dataType: "json",
                data: {
                    value: value,
                    csrfmiddlewaretoken: '{{ csrf_token }}'
                    },
            });
    }</script>

value gets to def sort_complect_table fine, right here:
def sort_complect_table(request):
    sort_zayavka = request.POST.get('value')
    print(value)
    sort_compl_table = ComplectTable.objects.filter(zayavka_number=sort_zayavka)
    return render(request, 'journal/komplekt_table.html', {"full_compl_table" : sort_compl_table})

everything that needs to be done, but when it comes to render - nothing on the page changes. Tell me what's the matter? I just tried ajax for the first time and maybe somewhere I didn’t understand the principle of the action. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-04-16
@bacon

Well, the ajax request returned the render to you (it works), and then you don’t do anything with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question