Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无限滚动脚本中的Jquery阅读更多按钮_Javascript_Php_Jquery_Mysql - Fatal编程技术网

Javascript 无限滚动脚本中的Jquery阅读更多按钮

Javascript 无限滚动脚本中的Jquery阅读更多按钮,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我正在制作一个包含用户生成内容的网站。内容基于文本,最受欢迎的帖子将出现在首页。由于帖子可能很长,我想添加一个“阅读更多”按钮。“阅读更多”按钮在加载的前10篇文章上运行良好,但在加载无限滚动脚本的文章上不起作用。用于阅读更多信息的jqueryplugini是 加载页面上前10篇文章的代码: <?php if($sql1){ while($row = mysqli_fetch_array($sql1)){ echo '<div id="postlist">

我正在制作一个包含用户生成内容的网站。内容基于文本,最受欢迎的帖子将出现在首页。由于帖子可能很长,我想添加一个“阅读更多”按钮。“阅读更多”按钮在加载的前10篇文章上运行良好,但在加载无限滚动脚本的文章上不起作用。用于阅读更多信息的jqueryplugini是

加载页面上前10篇文章的代码:

<?php
if($sql1){
    while($row = mysqli_fetch_array($sql1)){
        echo '<div id="postlist">
        <div style="width:400px; font-size:24px;">' . $row['title'] . '</div>
        <article class="slide">' . nl2br($row['post']) . '</article>
        <span style="float:right; margin-right: 10px;">+ ' . $row['totalupvotes'] . ' | - ' . $row['totaldownvotes'] . '</span>
        <br />
        by <a style="font-size:18px;" href="profile.php?id=' . $row['submittedby'] . '">' . $row['submitteduser'] . '</a>
         at <span style="font-size:12px;">' . $row['added'] . '</span><span style="float:right; margin-right: 10px;">' . $row['totalcomments'] . ' comments</span>
         </div>';
    }
}
?>
这是用于加载更多帖子的newquery.php脚本:

<?php
require_once("connect.php");
require_once("config.php");
$load = htmlentities(strip_tags($_POST['load'])) * 10;

$query = mysqli_query($connect,"SELECT * FROM posts WHERE totalupvotes < $trendmin AND deleted=0 ORDER BY added DESC LIMIT " . $load . ",10");

while($row = mysqli_fetch_array($query)){
    echo '<div id="postlist">
        <div style="width:400px; font-size:24px;">' . $row['title'] . '</div>
        <article class="slide">' . nl2br($row['post']) . '</article>
        <span style="float:right; margin-right: 10px;">+ ' . $row['totalupvotes'] . ' | - ' . $row['totaldownvotes'] . '</span>
        <br />
        by <a style="font-size:18px;" href="profile.php?id=' . $row['submittedby'] . '">' . $row['submitteduser'] . '</a>
         at <span style="font-size:12px;">' . $row['added'] . '</span><span style="float:right; margin-right: 10px;">' . $row['totalcomments'] . ' comments</span>
         </div>';
}




?>
我猜这个问题与无限滚动脚本(infinite scroll script)有关,它没有真正包含read more插件。我根本不擅长jquery,所以我只是下载并修改了这两个脚本


有什么想法吗?

好的。您应该做的可能是在事件触发时运行readmore:

将其也放入window.scroll事件中:


动态添加的文章不会像DOM就绪时绑定的那样进行绑定。尝试添加$article.readmore{…在你的$.post success函数中,这样它就绑定了新内容。哈哈哇…我在这里发帖之前确实试过你说的,但是如果我把$'article.readmore放在$'contentwrapper.appenddata.后面,它就行了!谢谢@SeanI不得不把$'article.readmore放在.appenddata行后面,除了$'article'.readmore标记位于无限滚动脚本之外。Thnx无论如何:
$('article').readmore({
          maxHeight: 75,
          speed: 300
        });
<?php
require_once("connect.php");
require_once("config.php");
$load = htmlentities(strip_tags($_POST['load'])) * 10;

$query = mysqli_query($connect,"SELECT * FROM posts WHERE totalupvotes < $trendmin AND deleted=0 ORDER BY added DESC LIMIT " . $load . ",10");

while($row = mysqli_fetch_array($query)){
    echo '<div id="postlist">
        <div style="width:400px; font-size:24px;">' . $row['title'] . '</div>
        <article class="slide">' . nl2br($row['post']) . '</article>
        <span style="float:right; margin-right: 10px;">+ ' . $row['totalupvotes'] . ' | - ' . $row['totaldownvotes'] . '</span>
        <br />
        by <a style="font-size:18px;" href="profile.php?id=' . $row['submittedby'] . '">' . $row['submitteduser'] . '</a>
         at <span style="font-size:12px;">' . $row['added'] . '</span><span style="float:right; margin-right: 10px;">' . $row['totalcomments'] . ' comments</span>
         </div>';
}




?>
$(window).scroll(function(){
        if($(window).scrollTop() == $(document).height() - $(window).height())
        {
            $("#loader").show();
            load++;
            if(load * 10 > nbr)
            {
                $("#messages").text("No more posts");
                $("#loader").hide();
            }
            else{
                $.post("php/newquery.php",{load:load},function(data){

                $("#contentwrapper").append(data);
                $("#loader").hide();
            });
            }
        }

    // HERE we also call readmore(), in addition to the first call on page load.
    $('article').readmore({
      maxHeight: 75,
      speed: 300
    });

    });