K
K
Kirill2020-05-03 15:47:32
Django
Kirill, 2020-05-03 15:47:32

Why is the data not updated via AJAX request?

I need a dynamic content update on the personal account page. Namely div'a with class and id start.
views.py file:

def orders_update(request):
    if request.is_ajax():
        temp_point_uid = request.POST['point_uid']
        if point.objects.filter(uid_point=temp_point_uid).exists():
            orders_count = order.objects.filter(point_id=temp_point_uid)
            context = {
                'orders_count': orders_count
            }
            print("updated")
            return render(request, 'lk_point.html', context)
    else:
        return Http404
    return HttpResponse()

AJAX request:
function load_orders() {
            $.ajax({
                url: "{% url 'orders_update' %}",
                type: "POST",
                data: {'point_uid': {{ point_uid }}, 'csrfmiddlewaretoken' : "{{csrf_token}}"},
                success: function () {
                    alert('updated');
                    $('#start').load;
                }
            });
        };

        setInterval(load_orders, 10000);

Updated is printed everywhere, but the content is not updated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentyn, 2020-05-03
@kustiktm_kirill

I guess the problem is here:

success: function () {
                    alert('updated');
                    $('#start').load;
                }

Try:
success: function (data) {
                    alert('updated');
                    $('#start').html(data);
                }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question