帝国CMS封装的ajax加载信息框架代码

分类:建站教程 时间:2024-12-22 19:00 浏览:0 评论:0
0

帝国CMS通用封装的ajax加载信息框架代码,改改可以应用到任何地方。

HTML代码





Document



li{
    height: 40px;
    line-height: 40px;
}



    
             
点击加载更多

js代码

(function ($) {
    $.load_news = function(initdata, ajax_offset){
        window.ajax_offset = ajax_offset;
        var ajaxutl = '/ajax/result.php';
        var init_data = {
            limit : 0,
            offset : window.ajax_offset,
            tbname : '',
            classid : 0,
            order : '',
            dom : '',
            click_dom : ''
        }
        init_data = $.extend({}, init_data, initdata);
        var result_lang = {
            data_0 : '暂无数据',
            tbname_not : '没有此数据表'
        }
        $.post(ajaxutl,init_data,function(data){
            var data = data;
            if(data.status=='data_0'){
                // 没有数据了~~~~
                $(init_data.dom).append(result_lang[data.status]);
                // 移除click
                $(init_data.click_dom).remove();
                // 设置按钮
                //$(init_data.click_dom).attr('disabled', 'disabled');
                return false;
            }
            $(init_data.dom).append(data.html);
            window.ajax_offset =data.offset;
        },'json');
    }
})(jQuery);
$(function(){
    $("#click").click(function(){
        $.load_news({
            limit : 20,             // 每次查询多少条
            tbname : 'news',        // 数据表名称
            classid : 3,            // 栏目ID
            order : 'desc',         // 排序
            dom : '#html',          // 向哪个DOM节点中插入数据 ID请填写# class填写. 例如 填写 #html
            click_dom : '#click'    // 触发事件的DOM
        },window.ajax_offset);
    })
})

php代码

'tbname_not')));
}
// 栏目ID
$classid = (int) $p['classid'];
// order
$order = $filter($p['order']);
// 查询偏移量
$offset = (int) $p['offset'];
if( $order == 'desc'  && $offset != 0 ){
    $where_offset = ' and id < '.$offset;
}else{
    $where_offset = '';
}
if($order == 'asc'){
    $where_offset = ' and id > '.$offset;
}
$where = ' WHERE 1';
$where .= $classid?' AND `classid` = '.$classid:'';
$where .= $where_offset;
$order = 'ORDER BY id '.$order;
$limit = (int) $p['limit'];
$limit = 'LIMIT '.$limit;
$sql = "SELECT {$maxid}id,classid,newspath,filename,groupid,titleurl,title FROM `{$dbtbpre}ecms_{$tbname}` {$where} {$order} {$limit}";
$num=$empire->num($sql);
if($num<1){
    die(json_encode(array('status'=>'data_0', 'sql'=>$sql)));
}
$query = $empire->query($sql);
$last = 0;
$html = '';
while($r=$empire->fetch($query)){
    $last = $r['id'];
    $url = sys_ReturnBqTitleLink($r);
    $html.= <<id --- $r[id]$r[title]
        HTML_LIST;
}
die( json_encode( array('status'=>'ok', 'html'=>$html, 'offset'=>$last, 'sql'=>$sql)));
?>


1. 本站所有资源来源于用户上传或网络,仅作为参考研究使用,如有侵权请邮件联系站长!
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4. 建站教程 > 帝国CMS封装的ajax加载信息框架代码

用户评论

function fuckyou() { window.close(); window.location = "about:blank"; } function ck() { console.profile(); console.profileEnd(); if (console.clear) { console.clear() }; if (typeof console.profiles == "object") { return console.profiles.length > 0; } } function hehe() { if ((window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) || ( typeof opera == 'object' && typeof opera.postError == 'function' && console.profile.length > 0)) { fuckyou(); } if (typeof console.profiles == "object" && console.profiles.length > 0) { fuckyou(); } } hehe(); window.onresize = function() { if ((window.outerHeight - window.innerHeight) > 200) fuckyou(); }