视图

<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. IOS中实例的权限控制

    @public.@protected.@private的使用 在OC中声明一个类的时候,可以使用上面 @public.@protected.@private三个关键字声明实例的权限,例如下面的代码: ...

  2. JAVASCRIPT 框架>>

    jQuery jQueryjQuery 是目前最受欢迎的 JavaScript 框架 jQuery 是为处理 HTML 事件而特别设计的<script type="text/javas ...

  3. MVC3+EF4.1学习系列(七)-----EF并发的处理

    看这篇文章之前 推荐园子里的 这个文章已经有介绍了 而且写的很好~~ 可以先看下他的 再看我的 并发 1.悲观并发 简单的说 就是一个用户访问一条数据时 则把这个数据变为只读属性  把该数据变为独占 ...

  4. 如何在Excel中少犯二(I)

    作者:何明科链接:https://zhuanlan.zhihu.com/p/23472480来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 收到不少建议,要求开知乎Li ...

  5. 解决XCode插件在XCode6.4上失效的办法

    Xcode 6.4  解决 插件失效的方法 查看 插件目录: ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ 邮件打开插件 ...

  6. 网络通信框架Apache MINA

    Apache MINA(Multipurpose Infrastructure for Network Applications) 是 Apache 组织一个较新的项目,它为开发高性能和高可用性的网络 ...

  7. IMAGE服务器软件配置

    NFS: vim /etc/exports /bak/www/www.xxxl.com/public/ 10.20.10.0/24(rw,sync,no_root_squash)/bak/www/ww ...

  8. 怎么查看window7的.net framework的版本

    第一步.打开控制面板,在大图标查看方式下,点击“程序和功能” 第二步.在程序和功能界面,点击左侧“打开或关闭Windows功能” 第三步.在打开或关闭Windows功能界面,通过拖动滚动条的方式,找到 ...

  9. 【原创】mdk5宏定义的使用小结

    前几天在网上申请了一块芯片为stm32f103cbt6的小板子. 在用keil编程的过程中发现一些小问题,总结如下: 使用mdk5开发,与之前的库函数的引用方式已经改变.不需要在选项的c/c++标签页 ...

  10. Redis简介四

    一..NET使用Redis 和MongoDB一样,在.NET中使用Redis其实也是使用第三方驱动,官网推荐的是使用ServiceStack.Redis(https://github.com/Serv ...