jave.web
jave.web

Reputation: 15052

Do not send Ajax request until same previous Ajax request is done

I want to load "more posts" dynamicly when user scrolls down the page to the last post. - this part is already done...

Thing is user can of course scroll back and forth, or just scroll again and again... This would cause multiple ajax requests when not needed yet.

How do I check if the same ajax call is not already running?

Upvotes: 0

Views: 1305

Answers (1)

Olim Saidov
Olim Saidov

Reputation: 2844

Just use something like this:

var loading = false;

var postLoader = function() {
    if (loading == false) {
        loading = true;

        $.ajax({

            // ajax options...

        }).always(function() {
            loading = false;
        });
    }
}

Upvotes: 3

Related Questions