在Codeigniter上滚动时加载 [英] Loading while scrolling on Codeigniter

查看:57
本文介绍了在Codeigniter上滚动时加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经消除了必须向控制器指示URL并使用url本身的变量var路径,现在路径错误消失了,但是我没有数据.文件通信中的某些内容没有被传递.

EDITS: I have eliminated the variable var path that I had to indicated the URL to the controller and used the url itself, now the path error is gone but I get no data. Something in the communication of the files is not being passed on.

我想做的是在滚动时,让页面从服务器加载数据.为此,我使用了一个单独的jquery文件,一个视图,控制器和模型.

What I am trying to do is upon scrolling, have the page load data from the server. For that purpose I am using a separate jquery file, a view, the controller and the model.

JQUERY文件.您将看到它非常简单:

JQUERY FILE. You will see it is pretty straightforward:

    $(document).ready(function() {

    var pageLoaded = 1; //this basically says that we are on page 1 of the results

      $(window).scroll(function()
       {

        if($(window).scrollTop() == $(document).height() - $(window).height())
        {
         pageLoaded = pageLoaded+1; //when this condition has met, increase the pageLoaded so that I can tell php to load in data for page 2/3/4/5, etc, etc

/*// below I send the data to the controller named Home its function loadData gets a variable named id_load with value = to pageLoaded*/

         $.get('home/loadData', {'id_load':pageLoaded}, 
            function(data)
            {
                if (data != "")
                {
                 $('#submissions').append(data);
                }
             }
         );
         //alert(pageLoaded);
        }
       }
      );


    });

控制器:

<?php if (! defined('BASEPATH')) exit ('No direct script access allowed');


class Home extends CI_Controller 
{
    function __construct()
    {

        parent::__construct();

        $this->load->model('load_model');
        $this->output->enable_profiler(TRUE);

    }


    public function loadData ()
    {
        $pageNumber = $this->input->get('id_load'); 
        $this->load_model->loadPage($pageNumber);

    }


    public function index()  
    {
      $data = array('title' =>'homepage', 'main_content' =>'home_v');
      $this->load->view('template', $data); 

    }



} 

,并且在滚动时,MODEL会在获取新值时显示内容:

and the MODEL should display the content as it gets new values while u scroll:

<?php


class Load_model extends CI_Model {



    public function loadPage ($pagenumber )

    {

        $sql = $this->db->where('id_load', $pagenumber)->get('data');

        $cadena = "";

        foreach($sql->result_array() as $reg)
        {
        $cadena =   $reg['content'];    

        }

        echo $cadena;


    }

}

推荐答案

尝试一下..

在标头<head>中,在顶部放置了一个base_url()的javascript变量.

in your header <head> put a javascript varaiable with base_url() at the top..

这里

html

<head>
  <script>
     var base_url=<?php echo base_url()?>;
  </script>
 ....
</head>

jquery

var path = base_url + 'index.php';

这篇关于在Codeigniter上滚动时加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆