在完成相同的先前Ajax请求之前,不要发送Ajax请求 [英] Do not send Ajax request until same previous Ajax request is done

查看:54
本文介绍了在完成相同的先前Ajax请求之前,不要发送Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户向下滚动页面到最后一个帖子时动态加载更多帖子".-这部分已经完成...

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

用户可以当然地来回滚动,或者只是一次又一次地滚动……这会在不需要时导致多个ajax请求.

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.

如何检查相同的ajax调用是否尚未运行?

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

推荐答案

只需使用以下内容:

var loading = false;

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

        $.ajax({

            // ajax options...

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

这篇关于在完成相同的先前Ajax请求之前,不要发送Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆