php ajax动态加载数据,php ajax 下拉加载数据

视图

健康知识

<?php foreach($result as $k => $res): ?>

<?php echo $result[$k]['hlh_url']; ?> <?php echo $result[$k]['title']; ?>
2186f15eb5c70d51255ea1fa1a6d1de3.gif
《加载动态图。。。。动态图是 div标签有一个gif格式的小图标》

$(function(){

function loadMeinv() {

var url = window.location.href;

$.get(url, {p: count, response: 'ajax'}, function (json) {

console.log(json);

$('#loading').fadeOut(3000);

setTimeout( function(){

if (json.length == 0) {

onOff = false;

return false;

} else {

count++;

}

$.each(json, function (keyList, ovalue) {

var html = '

'+ovalue.hlh_url+'
'

+'

'+ovalue.title+'
';

$minUl = getMinUl();

$minUl.append(html);

});

},1000);

}, 'json');

}

var onOff = true;

var count = 2;

// loadMeinv();

$(window).on("scroll", function () {

$minUl = getMinUl();

if (($(window).scrollTop() >= $minUl.height() - $(window).height()) && onOff && $('#loading').css('display') == "none") {

$('#loading').show();

loadMeinv();

}

});

function getMinUl() {

var $arrUl = $(".p-list");

var $minUl = $arrUl.eq(0);

$arrUl.each(function (index, elem) {

if ($(elem).height() < $minUl.height()) {

$minUl = $(elem);

}

});

return $minUl;

}

});

服务器的代码示例

控制器

/**

* 健康知识

*/

public function healthinfo(){

$data = array();

$page = $this->input->get('p') ? $this->input->get('p'):1;

$response = $this->input->get('response');

$type = "0";

$this->load->model('Xh_client_h5_model');

$data['result'] = $this->Xh_client_h5_model->get_healthinfo($type,$page);

if($response == 'ajax'){

echo json_encode($data['result']);die();

}

$this->load->view('healthinfo',$data);

}

模型

/**

* 获取健康知识的信息

* @param string $type 健康知识 0

* @param string $page

* @return 健康信息的列表

*/

public function get_healthinfo($type,$page){

$healthinfo = array();

$limit = 7;

$offset = ($page - 1) * $limit;

$this->db->where('type',$type);

$this->db->limit($limit, $offset);

$query = $this->db->get('hlh_message');

$row = $query->result_array();

foreach($row as $k=>$v){

$healthinfo[$k]['id'] = $v['id'];

$healthinfo[$k]['title'] = $v['title'];

$healthinfo[$k]['hlh_url'] = $v['hlh_url'];

$healthinfo[$k]['jump_url'] = $v['jump_url'];

}

return $healthinfo;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值