안녕하세요 저는 PHP/codeigniter와 내 메인 페이지 (모든 게시물이 표시되는 곳)에 코드가있는 블로그를 가지고 있습니다. 내 게시물에 무한 스크롤을 만들어서로드 할 수 있도록하고 싶습니다. 페이지 하단에 7 개 더 있습니다. 내 의견 showoul 부하에서 나를 위해 7 게시물아약스를 사용하여 내 블로그 홈 페이지의 무한 스크롤
public function index()
{
$data['posts'] = $this->Model_cats->getLivePosts(7);
$data['cats'] = $this->Model_cats->getTopCategories();
$data['title'] = 'Welcome';
$data['main'] = 'public_home';
$this->load->vars($data);
$this->load->view('template', $data);
}
public function index_show_post()
{
$data['posts'] = $this->Model_cats->getLivePosts(7);
$data['cats'] = $this->Model_cats->getTopCategories();
$data['title'] = 'Welcome';
$data['main'] = 'public_home';
$data['main2'] = 'public_home_loadpost';
$this->load->vars($data);
$this->load->view('template', $data);
}
함수 index_show_post() :
여기 내 컨트롤러입니다! 이것이 해결책인지는 모르지만 도움이 필요하다!
이
내 모델 :function getLivePosts($limit)
{
$data = array();
$this->db->limit($limit);
$this->db->where('status', 'published');
$this->db->order_by('pubdate', 'desc');
$query = $this->db->get('posts');
if($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
하고 뷰는 다음과 같습니다
<?php
if (count($posts))
{
foreach ($posts as $key => $list)
{
echo "<div class='postedComment'>";
echo '<h2>'.$list['title'].'</h2>';
echo auto_typography(word_limiter($list['body'], 200));
echo anchor('welcome/post/'.$list['id'],'read more >>');
echo "</div>";
}
echo '<br/><br/>';
}
?>
<div id='loadMoreComments' style="display:none;"></div>
와 나는이 일어날 수 있도록 할 Ajax를 사용하여 .. 자바 스크립트 파일을 jave :
을$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height()){
$('div#loadMoreComments').show();
$.ajax({
url: "<?php echo base_url()/welcome/index_show_post?>?lastComment=" + $(".postedComment:last").attr("id"),
success: function(html){
if(html)
{
$("#postedComments").append(html);
$('div#loadMoreComments').hide();
}
else
{
$('div#loadMoreComments').replaceWith("Finished Loading the comments");
}
}
});
}
});
코드 줄 :
url: "<?php echo base_url()/welcome/index_show_post?>?lastComment=" + $(".postedComment:last").attr("id"),
나는 컨트롤러를 호출하고 싶습니다! 하지만 그렇지 않습니다!
제안 사항?
친숙한 쪽지 - 창 스크롤 이벤트에 핸들러를 연결하지 마십시오. http://ejohn.org/blog/learning-from-twitter/ – LeonardChallis
조언을 주셔서 감사합니다. 그 외에,이 문제를 해결해 줄 수있는 제안이 있습니까? 아니면이 작품을 어떻게 만들 수 있는지에 대한 또 다른 예를 들어 주시겠습니까? 고마워요 – emcee22
http://stackoverflow.com/questions/13801197/load-more-content-from-an-array-using-codeigniter/13801594#13801594 여기에 대한 이전 답변이 있습니다. –