天天看點

帝國cms ajax,帝國CMS封裝的ajax加載資訊架構代碼

這篇文章主要為大家詳細介紹了帝國CMS封裝的ajax加載資訊架構代碼,具有一定的參考價值,感興趣的小夥伴們可以參考一下,有需要的朋友可以收藏友善以後借鑒。

給大家分享一段帝國CMS通用封裝的ajax加載資訊架構代碼,自己動手改改可以應用到任何地方。

帝國cms ajax,帝國CMS封裝的ajax加載資訊架構代碼

HTML代碼:html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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代碼:<?php

include '../e/class/connect.php'; // 資料庫配置檔案與公共函數檔案

include '../e/class

_sql.php'; // 資料庫操作檔案

include '../e/data

cache/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 

}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) ) );

?>

以上就是帝國CMS封裝的ajax加載資訊架構代碼的全部内容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支援361模闆網。

感謝打賞,我們會為大家提供更多優質資源!