javascript On 向下滚动如何进行 ajax 调用并获取响应数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8687978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:13:54  来源:igfitidea点击:

On Scroll down how to make ajax call and get the respone data

javascriptajaxjquery-uijquery

提问by Deept Raghav

Please can you people guide me how to make ajax call when scroll down

请你们指导我如何在向下滚动时进行ajax调用

回答by Deept Raghav

var no=1;
$(window).scroll(function () {
    if(no==1)
    {
        if ($(window).height() + $(window).scrollTop() == $(document).height()) {
            no=2;
            $.ajax({
                type: "POST",
                url: "request.php",
                data: datas,
                cache: false,
                success: function(html){

                }
            });
        }
    }
});

This does an ajax call when a user reaches at end of page.

当用户到达页面末尾时,这会执行 ajax 调用。

You can specify a height at which it occurs.

您可以指定它发生的高度。

回答by abelito

Here is a separate stack overflow question about firing events on scrolling:

这是一个关于在滚动时触发事件的单独堆栈溢出问题:

jQuery window scroll event does not fire up

jQuery 窗口滚动事件没有启动

And here is jquery's manual that shows how to use ajax:

这是 jquery 的手册,展示了如何使用 ajax:

http://api.jquery.com/jQuery.ajax/

http://api.jquery.com/jQuery.ajax/

Combine and enjoy!

结合享受!