1、静态页面下调用动态页面内容

例如在某个静态html页面中想调用动态内容时,可以将下面代码放到它页面里:

<div id="ajax_test_file">
{dr_ajax_template("ajax_test_file", "test.html")}

意思是调用test.html的内容,作为动态调用模式,那么你需要在test.html写你的代码。


2、ajax动态加载模式,例如搜索页面无刷新滚动加载下一页

<script src="需要百度搜索找到这个js库 dropload.min.js"></script>
<input id="dr_page_id" type="hidden" value="2">
<script>
    $(function(){

        // dropload
        var dropload = $('.content').dropload({
            scrollArea : window,
            loadDownFn : function(me){
                $.ajax({
                    type: 'GET',
                    url: '/index.php?s=api&c=api&m=template&name=items.html&module={MOD_DIR}&catid={$catid}&sototal={$sototal}&searchid={$searchid}&order={$params.order}&page='+$('#dr_page_id').val(),
                    dataType: 'jsonp',
                    success: function(json){

                        $('.sd-item-list').append(json.msg);
                        // 每次数据加载完,必须重置
                        me.resetload();
                        
                        $('#dr_page_id').val(Number($('#dr_page_id').val())+1);

                    },
                    error: function(xhr, type){
                        alert('Ajax error!');
                        // 即使加载出错,也得重置
                        me.resetload();
                    }
                });


            }
        });
    });
</script>

然后在api/items.html写上第二页的查询代码

<?php $get=$_GET;?>
{search module=$get.module id=$get.searchid total=$get.sototal order=$get.order catid=$get.catid page=1 pagesize=20 urlrule=$urlrule}
<li>
    <a href="{dr_mobile_url($t.url)}">
        <div class="sd-item-img"><img src="{dr_thumb($t[thumb][0][file], 100, 100)}"></div>
        <div class="sd-item-body">

            <div class="sd-item-body-name">
                <span>{$t.title}</span>
            </div>
            <div class="product-price-m">
                <em>¥
                    <span class="big-price">{number_format($t.price, 2)}</span>
                </em>
                <i class="plus-p"></i>
            </div>
            <div class="gray-pro-info">
                <span>{$t.comments}条评价</span>
                <span>{$t.volume}销量</span>
            </div>

        </div>
    </a>
</li>
{/search}


文档最后更新时间:2017-02-28 14:24:14