首页 > CMS建站 > 帝国Empire > 正文

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

2020-07-02 22:22:42
字体:
来源:转载
供稿:网友
这篇文章主要为大家详细介绍了帝国CMS封装的ajax加载信息框架代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。

     给大家分享一段帝国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 : '没有此<a href="http://www.cuoxin.com/tags/sjb/" target="_blank">数据表</a>'}$.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', // <a href="http://www.cuoxin.com/tags/sjb/" target="_blank">数据表</a>名称classid : 3, // 栏目IDorder : 'desc', // 排序dom : '#html', // 向哪个DOM节点中插入数据 ID请填写# class填写. 例如<div id="html"> 填写 #htmlclick_dom : '#click' // 触发事件的DOM},window.ajax_offset);})})

php代码:

<?phpinclude '../e/class/connect.php'; // 数据库配置文件与公共函数文件include '../e/class_sql.php'; // 数据库操作文件include '../e/datacache/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) ) );?>
以上就是帝国CMS封装的ajax加载信息框架代码的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持错新网。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表