dp926460 2017-06-04 17:17
浏览 55

使用Ajax,PHP和MySQL进行无限滚动时出错

I am trying to implement an infinite scroll in my application but at the moment of reaching the end of my page, this throws the error that places.

This is the ajax code:

<script type="text/javascript">
    $(window).scroll(function() {
        if($(window).scrollTop() + $(window).height() >= $(document).height()) {
            var last_id = $(".post-id:last").attr("id");
            loadMoreData(last_id);
        }
    });

    function loadMoreData(last_id){
      $.ajax(
            {
                url: '/loadMoreData.php?last_id=' + last_id,
                type: "get",
                beforeSend: function()
                {
                    $('.ajax-load').show();
                }
            })
            .done(function(data)
            {
                $('.ajax-load').hide();
                $("#post-data").append(data);
            })
            .fail(function(jqXHR, ajaxOptions, thrownError)
            {
                  alert('server not responding...');
            });
    }
</script>

Here, is where I show the data from th DataBase:

<?php while ($post = $result -> fetch(PDO::FETCH_ASSOC)){ ?>

    <div class="box-list" id="post-data">
        <div class="item">
            <div class="row">
              <p class="post-id hidde" id="<?php echo $post['id']; ?>">
                <div class="col-md-1 hidden-sm hidden-xs">
                    <div class="img-item"><img src="<?php echo OTRA; ?>/images/<?php echo $post['thumb']; ?>" alt=""></div>
                </div>
                <div class="col-md-11">
                    <h3 class="no-margin-top"><a href="single.php?id=<?php echo $post['id']; ?>"><?php echo $post['titulo']; ?> <i class="fa fa-link color-white-mute font-1x"></i></a></h3>
                    <h5><span class="color-black"><?php echo $post['company']; ?></span> - <span class="color-white-mute"><?php echo $post['locacion']; ?></span></h5>
                    <p class="text-truncate "><?php echo $post['extracto']; ?></p>
                    <div>
                    <span class="color-white-mute"><?php echo fecha($post['fecha']); ?></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php } ?>

and this id the other PHP file to load more data:

<?php session_start();

require 'extras/config.php';
require 'functions.php';

comprobarSession();

$conexion = conexion($bd_config);

$qry = "SELECT * FROM publications WHERE id > '$_GET['last_id']' ORDER BY id DESC LIMIT 8";
$result = $conexion->query($qry);
print_r ($result);

$json = include('views/empleos.php');

echo json_encode($json);

on the Developer Tool of Chrome the error that show me is

jquery.js:8706 GET http://localhost/loadMoreData.php?last_id=9 404 (Not Found)

  • 写回答

1条回答 默认 最新

  • douzhe9927 2017-06-05 01:35
    关注

    What is the name of that php file? Sounds like it is not loadMoreData.php? Perhaps it is loadData.php, and the AJAX call should be changed?

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭