您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程

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

凝天2023-05-30帝国CMS教程已有人查阅

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="/ajax/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="/ajax/loadNews.js" type="text/javascript"></script>
<style type="text/css">
li{
height: 40px;
line-height: 40px;
}
</style>
</head>
<body>
<div id="html"></div>        
<div><button id="click">点击加载更多</button></div>
</body>
</html>

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 : '<font color="red" size="+1">暂无数据</font>',
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填写. 例如<div id="html"> 填写 #html
click_dom : '#click'        // 触发事件的DOM
},window.ajax_offset);
})
})

php代码

<?php
include '../e/class/connect.php';        // 数据库配置文件与公共函数文件
include '../e/class/db_sql.php';        // 数据库操作文件
include '../e/data/dbcache/class1.php';        // 栏目缓存文件
$link = db_connect();        // 链接数据库
$empire = new mysqlquery();        // 实例化数据库操作类
$p = $_POST;                                                // 简写post
$_POST = null;                                                // 释放post
$filter = 'RepPostVar';                                // 过滤非法数据
$tbname = $filter($p['tbname']);        // 数据表名
// 判断表是否存在
if( !$tbname || in_array($tbname, $etable_r) )
{
die( json_encode( array('status'=>'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.= <<<HTML_LIST
<li>id --- $r[id]<a href="{$url}">$r[title]</a></li>
HTML_LIST;
}
die( json_encode( array('status'=>'ok', 'html'=>$html, 'offset'=>$last, 'sql'=>$sql) ) );
?>

本文标签:

很赞哦! ()

相关源码

  • (自适应多语言)WordPress开源主题MirageV资讯个人博客源码MirageV资讯类个人博客主题源码/WordPress主题/全开源MirageV 是一款开源的 WordPress 主题,支持自适应、暗黑模式、多语言等功能,查看源码
  • (自适应)APP应用软件落地页单页推广页网站模板下载基于PbootCMS内核开发的响应式单页模板,为企业产品展示、服务推广等应用场景设计。通过简洁直观的视觉布局与高效的技术架构,帮助用户快速构建专业级落地页面,实现移动端与PC端数据实时同步展示。查看源码
  • (自适应响应式)英文外贸医疗科研耗材设备pbootcms网站模板为医疗设备和外贸企业设计的响应式网站模板,基于PbootCMS系统开发。突出医疗产品认证展示和国际化特性,通过专业化的产品参数展示模块和文档管理系统,满足医疗行业严格的信息披露要求。查看源码
  • (自适应)居家生活日用品纸盘纸盒纸杯卫生纸巾生产厂家pbootcms模板为纸品生产企业打造的现代化展示平台,自动适应各种设备屏幕,确保浏览体验一致,完善的SEO功能,提升网站曝光度,基于PbootCMS构建,源码开放可定制。查看源码
  • pbootcms模板(PC+WAP)微信小程序开发公司网站本模板为微信小程序开发代理、软件开发公司等企业设计,基于PbootCMS内核开发,支持PC+WAP双端响应式布局,数据实时同步,适用于多行业快速建站。查看源码
  • 帝国cms7.5游戏门户H5小游戏网站模板源码免费下载基于帝国CMS7.5开发的H5游戏门户模板,为在线游戏平台设计。支持PC端与移动端同步生成,打造完整的游戏娱乐体验平台。查看源码
分享笔记 (共有 篇笔记)
验证码: