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

 5738

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

HTML代码

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  5. <title>Document</title>
  6. <script src="/ajax/jquery-1.11.2.min.js" type="text/javascript"></script>
  7. <script src="/ajax/loadNews.js" type="text/javascript"></script>
  8. <style type="text/css">
  9. li{
  10.     height: 40px;
  11.     line-height: 40px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16.     <div id="html"></div>        
  17.     <div><button id="click">点击加载更多</button></div>
  18. </body>
  19. </html>

js代码

  1. (function ($) {
  2.     $.load_news = function(initdata, ajax_offset){
  3.         window.ajax_offset = ajax_offset;
  4.         var ajaxutl = '/ajax/result.php';
  5.         var init_data = {
  6.             limit : 0,
  7.             offset : window.ajax_offset,
  8.             tbname : '',
  9.             classid : 0,
  10.             order : '',
  11.             dom : '',
  12.             click_dom : ''
  13.         }
  14.         init_data = $.extend({}, init_data, initdata);
  15.         var result_lang = {
  16.             data_0 : '<font color="red" size="+1">暂无数据</font>',
  17.             tbname_not : '没有此<a href="http://www.zztuku.com/tags/sjb/" target="_blank">数据表</a>'
  18.         }
  19.         $.post(ajaxutl,init_data,function(data){
  20.             var data = data;
  21.             if(data.status=='data_0'){
  22.                 // 没有数据了~~~~
  23.                 $(init_data.dom).append(result_lang[data.status]);
  24.                 // 移除click
  25.                 $(init_data.click_dom).remove();
  26.                 // 设置按钮
  27.                 //$(init_data.click_dom).attr('disabled', 'disabled');
  28.                 return false;
  29.             }
  30.             $(init_data.dom).append(data.html);
  31.             window.ajax_offset =data.offset;
  32.         },'json');
  33.     }
  34. })(jQuery);
  35. $(function(){
  36.     $("#click").click(function(){
  37.         $.load_news({
  38.             limit : 20,             // 每次查询多少条
  39.             tbname : 'news',        // <a href="http://www.zztuku.com/tags/sjb/" target="_blank">数据表</a>名称
  40.             classid : 3,            // 栏目ID
  41.             order : 'desc',         // 排序
  42.             dom : '#html',          // 向哪个DOM节点中插入数据 ID请填写# class填写. 例如<div id="html"> 填写 #html
  43.             click_dom : '#click'    // 触发事件的DOM
  44.         },window.ajax_offset);
  45.     })
  46. })

php代码

  1. <?php
  2. include '../e/class/connect.php';           // 数据库配置文件与公共函数文件
  3. include '../e/class/db_sql.php';            // 数据库操作文件
  4. include '../e/data/dbcache/class1.php';     // 栏目缓存文件
  5. $link = db_connect();                       // 链接数据库
  6. $empire = new mysqlquery();                 // 实例化数据库操作类
  7. $p = $_POST;                                // 简写post
  8. $_POST = null;                              // 释放post
  9. $filter = 'RepPostVar';                     // 过滤非法数据
  10. $tbname = $filter($p['tbname']);            // 数据表名
  11. // 判断表是否存在
  12. if(!$tbname || in_array($tbname, $etable_r)){
  13.     die(json_encode( array('status'=>'tbname_not')));
  14. }
  15. // 栏目ID
  16. $classid = (int) $p['classid'];
  17. // order
  18. $order = $filter($p['order']);
  19. // 查询偏移量
  20. $offset = (int) $p['offset'];
  21. if( $order == 'desc'  && $offset != 0 ){
  22.     $where_offset = ' and id < '.$offset;
  23. }else{
  24.     $where_offset = '';
  25. }
  26. if($order == 'asc'){
  27.     $where_offset = ' and id > '.$offset;
  28. }
  29. $where = ' WHERE 1';
  30. $where .= $classid?' AND `classid` = '.$classid:'';
  31. $where .= $where_offset;
  32. $order = 'ORDER BY id '.$order;
  33. $limit = (int) $p['limit'];
  34. $limit = 'LIMIT '.$limit;
  35. $sql = "SELECT {$maxid}id,classid,newspath,filename,groupid,titleurl,title FROM `{$dbtbpre}ecms_{$tbname}` {$where} {$order} {$limit}";
  36. $num=$empire->num($sql);
  37. if($num<1){
  38.     die(json_encode(array('status'=>'data_0', 'sql'=>$sql)));
  39. }
  40. $query = $empire->query($sql);
  41. $last = 0;
  42. $html = '';
  43. while($r=$empire->fetch($query)){
  44.     $last = $r['id'];
  45.     $url = sys_ReturnBqTitleLink($r);
  46.     $html.= <<<HTML_LIST
  47.         <li>id --- $r[id]<a href="{$url}">$r[title]</a></li>
  48.         HTML_LIST;
  49. }
  50. die( json_encode( array('status'=>'ok', 'html'=>$html, 'offset'=>$last, 'sql'=>$sql)));
  51. ?>


本文网址:https://www.zztuku.com/detail-7717.html
站长图库 - 帝国CMS封装的ajax加载信息框架代码
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐