S
S
Sergey08082017-10-17 10:39:55
JavaScript
Sergey0808, 2017-10-17 10:39:55

Python Django how to create link url in ajax method?

There is a link in the template

<a class="lazy_ajax" href="{% url 'news:lazy_ajax' %}" data-page="2">Показать еще</a>

js:
let button = $('a.lazy_ajax');
    button.click(function () {
        let link = $(this);
        let page = link.data('page');

       $.ajax({
           type: 'GET',
          url: $(this).attr('href'),

But for some reason a get request is sent, and I need an asynchronous request, but if I specify the url in this format - '../news/ajax/lazy_load/' then everything works. How can I set a link in the first place?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-10-17
@Sergey0808

button.click(function(event) {
    event.preventDefault();
    ...
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question