E
E
Egor Larin2018-06-10 10:16:04
Django
Egor Larin, 2018-06-10 10:16:04

Where can I get an example of how ajax works in django?

please give a link to a simple full!!! an example of how ajax works in django (which shows the work in templates and in views and in urls) so that you can copy-paste and see what's what. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2018-06-10
@biznesko

There is no need to write anything in the settings. Just access the request via AJAX.
For example using jQuery:

$(window).ready(function () {
    $("#somebutton").click(function(){
        $.get("test/", {}, function (data) {
            $("#somediv").html(data);
        });
    });
});

This code assumes that you are accessing the server along the path 'test/' when clicking on an element with id 'somebutton'. And the data received from the server is added to the element with id 'somediv'.
Django determines whether an ajax request is made or not with an X-Requested-With header with a value of "XMLHttpRequest". Request ostensibly via AJAX this way can be done with cURL or Postman

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question