编辑:我已经消除了我必须向控制器指示 URL 并使用 url 本身的变量 var path,现在路径错误消失了,但我没有得到任何数据。文件通信中的某些内容没有被传递。
我想要做的是在滚动时,让页面从服务器加载数据。为此,我使用了一个单独的 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;
}
}