php - Zend框架2:在滚动上加载数据

php - Zend框架2:在滚动上加载数据,第1张

我想在页面底部滚动加载数据(图像和一些文本)。我正在使用Zend 2框架和html" class="superseo">jquery

视图

<section>
    <?php
    $total_groups = ceil($count / 10);
    ?>
    <script type="text/javascript">
        $(document).ready(function () {
            var track_load = 0; //total loaded record group(s)
            var loading = false; //to prevents multipal ajax loads
            var total_groups = <?php echo $total_groups; ?>; //total record group(s)

            $('#results').load("/autoload_process.php", {'group_no': track_load}, function () {
                track_load  ;
            }); //load first group

            $(window).scroll(function () { //detect page scroll

                if ($(window).scrollTop()   $(window).height() == $(document).height())  //user scrolled to bottom of the page?
                {

                    if (track_load <= total_groups && loading == false) //there's more data to load
                    {
                        loading = true; //prevent further ajax loading
                        $('.animation_image').show(); //show loading image

                        //load data from the server using a HTTP POST request
                        $.post('/autoload_process.php', {'group_no': track_load}, function (data) {

                            $("#results").append(data); //append received data into the element

                            //hide loading image
                            $('.animation_image').hide(); //hide loading image once data is received

                            track_load  ; //loaded group increment
                            loading = false;

                        }).fail(function (xhr, ajaxOptions, thrownError) { //any errors?

                            alert(thrownError); //alert with HTTP error
                            $('.animation_image').hide(); //hide loading image
                            loading = false;

                        });

                    }
                }
            });
        });
    </script>
    <ol id="results">
    </ol>
    <div class="animation_image" style="display:none" align="center">
        <img src="/images/loader.gif">
    </div>
    <!-- IT SHOULD LOOK LIKE THIS
    <?php foreach ($works as $work) : ?>
            <img src="/images/works/<?php echo $this->escapeHtml($work->imgSrc); ?>" />
    <?php endforeach; ?>
    -->
</section>

autoload_process.php

<?php
$items_per_group = 10;
if ($_POST) {
    //sanitize post value
    $group_number = filter_var($_POST["group_no"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);

    //throw HTTP error if group number is not valid
    if (!is_numeric($group_number)) {
        header('HTTP/1.1 500 Invalid number!');
        exit();
    }

    //get current starting point of records
    $position = ($group_number * $items_per_group);

    //Limit our results within a specified range. 
    $results = $mysqli->query("SELECT id,name,alt as message FROM works ORDER BY id ASC LIMIT $position, $items_per_group");

    if ($results) {
        //output results from database

        while ($obj = $results->fetch_object()) {
            echo '<li id="item_' . $obj->id . '">' . $obj->id . ' - <strong>' . $obj->name . '</strong></span> &mdash; <span class="page_message">' . $obj->message . '</span></li>';
        }
    }
    unset($obj);
    $mysqli->close();
}
?>

我不认为从jquery调用autoload_process.php是如何在Zend2中加载文件的最佳方法。我想我应该以某种方式调用我的控制器或我的表功能,但还没有运气。

最佳答案:

0 个答案:

没有答案
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
教程弟学习网站 » php - Zend框架2:在滚动上加载数据

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情