I
I
Igor Peregudov2017-04-21 18:16:16
JavaScript
Igor Peregudov, 2017-04-21 18:16:16

How to "kill" ajax request on event when working with api?

How to stop the request on an event, such as a click?
and immediately after the second question? how not to cache these requests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nik Gubin, 2017-04-21
@igorperegudov

// Ajax запрос (или $.post, $.get и другие методы)
var ajax = $.ajax({ ... });

$('#click').on('click', function () {
    // Проверка, что запрос есть и ещё не завершён
    if (ajax && ajax.readyState != 4) {
        ajax.abort(); // Отмена запроса
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question