视图

<html>

<head>
<title>健康知识</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div>
<ul class="et-list p-list">
<?php foreach($result as $k => $res): ?>
<li><?php echo $result[$k]['hlh_url']; ?></li><br/>
<li><a href="http://xhdoctor.ci.com/index.php/xh_client_h5/healthinfoc?id=<?php echo $result[$k]['id']; ?>"><?php echo $result[$k]['title']; ?></a></li><br />
<?php endforeach; ?>
</ul>
</div>
<div id="loadingbox"><img id="loading" style="display:none;height:20px;" src="http://img.lanrentuku.com/img/allimg/1212/5-121204193R0.gif"/></div> 《加载动态图。。。。动态图是 div标签有一个gif格式的小图标》
<script>
$(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 = '<li>'+ovalue.hlh_url+'</li><br/>'
+'<li><a href="http://xhdoctor.ci.com/index.php/xh_client_h5/healthinfoc?id='+ovalue.id+'">'+ovalue.title+'</li><br />';
$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;
}
});

</script>
</body>
</html>

服务器的代码示例

控制器

/**
* 健康知识
*/
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;
}

php ajax 下拉加载数据的更多相关文章

  1. Ajax 下拉加载数据

    $(document).scroll(function() { var pageHeight = $(document).height()-$(window).height(); var bodySc ...

  2. iscroll5 上拉,下拉 加载数据

    我这里的思路是上拉时候只是加载第一页的内容,可根据实际情况修改其中的代码.请勿照搬.样式没怎么调,可以加载gif动画.1.没有数据时候,下拉可以加载数据.2.没有数据时候,点击也可以加载数据.3.其余 ...

  3. Jquery手机下拉刷新,下拉加载数据

    一.Jquery手机下拉刷新,下拉加载数据.附加有源码 <!DOCTYPE html> <html> <head> <title>手机</titl ...

  4. 关于MJRefresh的下拉加载数据bug

    当没有更多数据的时候显示NoMoreData 我的理解是先结束刷新再显示没有更多 今天之前一直没发现有问题 贴之前的代码 [self.collectionView reloadData]; [self ...

  5. web移动端下拉加载数据简单实现

    //下拉加载在移动端会经常使用,有些小伙伴不清楚一些原理下面就简答的介绍一下 //首先需要监听window的滚动事件,下拉其实就是在监听window滚动事件 var pageNum = 1;//分页第 ...

  6. 手机网站下拉加载数据js(简单版)

    加载内容的地方html <div class="bgcolor_f0 clearfix"> <div class="recharge"> ...

  7. iscroll5 版本下的 上拉,下拉 加载数据

    上拉时候只是加载第一页的内容,可根据实际情况修改其中的代码. <section id="downwraper" class="nodeBottom bot0 bgf ...

  8. juqery 下拉加载数据

    html  代码  一开始是需要显示的第一页 <div class="hot-product f15 fixed-Width clearfix" id="goods ...

  9. ajax 下拉加载更多效果

    1.生成HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

随机推荐

  1. COCOA® PROGRAMMING FOR MAC® OS X (1)- Get Start

    这个是Mac OS App开发学习的第一篇,希望是一个好的开始. 一.为什么要学习Mac OS App开发 a)长时间做IOS开发,发现自己所做的局限在苹果的一些库上面,一些底层的API却是私有的,不 ...

  2. 七牛 在线管理 v0.1

    <?php // @codingStandardsIgnoreFile require_once __DIR__.'/../vendor/autoload.php'; use Qiniu\Aut ...

  3. Django 基础知识

    Django Models django 本身提供了非常强大易使用的ORM组件,并且支持多种数据库,如sqllite,mysql,progressSql,Oracle等,当然最常用的搭配还是mysql ...

  4. html各元素中的区别

    HTML中DIV与SPAN的区别 html的div和span, 经常会用到, 尤其是前者. 1. div是块级元素, 实际上就是一个区域, 主要用于容纳其他标签. 默认的display属性是block ...

  5. Copy Constructor的构造操作

    Copy Constructor的构造操作 有三种情况,会以一个object的内容作为另一个class object的初值: 1.  对一个object做显式的初始化操作 class X{…}; X ...

  6. wordpress建站过程1

    使用wordpress我们需要理解一些概念: 1.WordPress是一种使用PHP语言开发的博客平台,它的程序是由php构成的,所以想要使用word press必须会php. 2.Wordpress ...

  7. python2.7学习记录

    一.两个学习网址(2.7已经过时,建议直接学习3) http://blog.csdn.net/longxibendi/article/details/41949215 http://www.liaox ...

  8. Windows进程间通信(上)

    一.管道 管道(pipe)是用于进程间通信的共享内存区域.创建管道的进程称为管道服务器,而连接到这个管道的进程称为管道客户端.一个进程向管道写入信息,而另外一个进程从管道读取信息. 异步管道是基于字符 ...

  9. Android 调试工具集【转】

    1.TraceView1)功能:用于热点分析和性能优化,分析每个函数占用的CPU时间,调用次数,函数调用关系等 2)方法: a)在程序代码中加入追踪开关 import android.os.Debug ...

  10. Chapter 2 Open Book——19

    He bent over and began scraping together a pile of the white mush. 他弯下腰,开始团起一个白色的雪球. "I'll see ...