使用codeigniter从数组加载更多的内容 [英] load more content from an array using codeigniter
问题描述
我使用CodeIgniter。在我的控制器,我解码一个JSON响应,只是显示的值加载视图。我只是显示所有我的内容从JSON数组(没有数据库使用)。
I am using CodeIgniter. In my controller I am decoding a JSON response and simply displaying the values upon loading a view. I am simply displaying all my content from a JSON array (no database used). It is completely an array from which i am rendering the data.I want to autoload the content whilst scrolling.
示例:
$resultjson = $this->curl->simple_get("http://www.test.com/api/records.php?ak=XXXXXXXX&ts=XXXXXXXX&sig=XXXXXXXX&postano=XXXXXX&count=100");
自动加载时如何获取10条记录?就像 http://pinterest.com/ 机制。如何实现这一点?
How can I fetch 10 records when autoloaded? Just like the http://pinterest.com/ mechanism. How can I achieve this?
有没有插件?
推荐答案
您可以使用 jQuery滚动事件, scrollTop()和$ .ajax();
You can use the jQuery scroll event, scrollTop() and the $.ajax();
基本上捕获滚动事件,看是否 $(window).scrollTop()
高于< div id =auto_load> / div>
(通过 .offset()),然后运行ajax一次
Basicly catch the scroll event, see if $(window).scrollTop()
is higher than <div id="auto_load"></div>
(through .offset()) and run ajax once if that's the case.
div#auto_load
将是加载内容的地方,并会
div#auto_load
would be places bellow loaded content, and will "jump" down once content is added.
示例:
var ajax_once = false;
$(window).bind('scroll', function() {
if (ajax_once)
return;
if ($(this).scrollTop() >= $('div#auto_load').offset().top) {
ajax_once = true;
$.ajax({
/* Url, dataType json etc. */
}).done(function(data) {
/* use the data */
ajax_once = false;
});
}
});
这篇关于使用codeigniter从数组加载更多的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!