搜尋#keyword和載入內容地區#ajax_lists
<input id="keyword" class="input" type="text" value="" placeholder="請輸入搜尋關鍵詞" />
<input class="btn" type="button" value="搜尋" />
var url_ajax = "__APP__/Box/orders";
$(function() {
$("#ajax_lists").delegate(".pager a", "click", function() {
var page = $(this).attr("data-page");//擷取當前點擊分頁
getPage(page);
})
getPage(1); //初始化分頁
})
function getPage(page) {
$("#ajax_lists").html("
loading
"); var keyword = $("#keyword").val(); $.get(url_ajax, {keyword: keyword, p: page}, function(data) { $('#ajax_lists').html(data); }) }
遠程ajax載入訂單列表
public function orders() {
$sql = "1=1";
$keyword = trim(I('get.keyword'));
if (!empty($keyword)) {
$sql .= " AND name like '%" . $keyword . "%'";
}
$count = M('js')->where($sql)->count(); //計算總數
$Page = new \Think\PageAjax($count, 10);
//
$lists = M('js')->where($sql)->limit($Page->firstRow . ',' . $Page->listRows)->order('id DESC')->select();
$this->assign("page", $Page->show());
$this->assign("lists", $lists);
$this->assign("keyword", $keyword);
$this->display();
}
如圖: