所以我遵循了旧的youtube教程,但无法完全做到。我没有什么负担。基本上,我想做的是从网页上的数据库中发布3或5个数据,然后当用户向下滚动时,它将加载更多数据(我想让按钮声明(加载更多),然后调用该函数来加载它)。
现在,我的网页是空白的,什么也没有弹出,甚至是错误,什么也没有。
徘徊了将近一个小时,换了东西,仔细检查,但无济于事。
非常感谢您的协助:)
这是我的index.php

    <!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags always come first -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">


    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            //var to auto-increment
                var flag = 0;

                $.ajax({
                    type: "GET",
                    url: "get_data.php",
                    data:{
                        'offset': 0,
                        'limit': 3
                    },
                    success: function(data){
                        $('body').append(data);
                        flag += 3;
                    }

                });

                $(window).scroll(function(){

                    if($(window).scrollTop() >= $(document).height() - $(window).height()){

                    $.ajax({

                        type: "GET",
                        url: "get_data.php",
                        data:{
                            'offset': flag,
                            'limit': 3
                            },
                        success: function(data){
                        $('body').append(data);
                        flag += 3;
                            }

                    });

                }
        });
    </script>

    <style type="text/css">

        .blog-post{
            border-bottom: solid 4px black;
            margin-bottom: 20px;
        }
        .blog-post h1{
            font-zise: 40px;
        }
        .blog-post p{
            font-size: 30px;
        }
    </style>


 </head>
  <body>

  </body>
</html>


请参阅“ get_data.php”的链接:https://pastebin.com/MYz2bjFN
jquery.min.js和get_data.php都在同一文件夹中。
数据库已存在。

最佳答案

找出问题所在。
我使用了chrome的开发人员工具并检查了网络标签,发现没有打印错误的主要原因是因为$(window).scroll(function(){...没有结束标记)之前 。

非常感谢Magnus Eriksson。

10-04 22:30
查看更多