EDITS:我已经消除了,我不得不指出的URL到控制器,并使用URL本身,现在的路径错误走了,但我没有得到任何数据变量var路径。 东西在文件中的通信不被通过。
我所试图做的是在滚动,有来自服务器的页面加载数据。 为了这个目的,我使用一个单独的jQuery的文件,视图,控制器和模型。
JQUERY文件。 你会看到它是非常简单的:
$(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);
}
}
并且,因为它得到新的值,而ü滚动模式应该显示的内容:
<?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;
}
}