[eluser]condoace[/eluser]
I am having an issue with loading data into a view after an AJAX request has been. I checked Firebug and the ajax call returns 200 OK, but no new data is loading, it just shows the same data and the page links dont change, i.e. only stays on page 1.
VIEW
Code:
[javascript]
// Functon to Show out Busy Div
function showBusy(){
$('#ajax-content').block({
message: '<h1>Processing</h1>',
css: {border:'3px solid #000'}
});
}
function updatePage(html){
window.setTimeout( function(){
$('#ajax-content').html(html);
}, 2000)
}
$(document).ready(function() {
// $.AJAX Example Request
$('#ajax-pag').live('click', function(eve){
eve.preventDefault();
var link = $(this).attr('href');
$.ajax({
url: link,
type: "GET",
dataType: "html",
beforeSend: function(){
showBusy();
},
success: function(html) {
updatePage(html);
}
});
});
});
[javascript]
</head>
<body>
<!--end header -->
<div id="ajax-content">
<?php
foreach ($results as $r){
?>
<div class="search_result">
<div><?php echo $r->address;?></div>
<div> <?php echo $r->email;?></div>
</div>
<?php
}
echo'<ul id="ajax-pag">';
echo $pag_links;
echo '</ul>';
?>
</div>
CONTROLLER
Code:
class Search extends CI_Controller {
function __construct()
{
parent:: __construct();
$this->load->library('pagination');
$this->load->model('Rooms_model');
}
function index($offset='')
{
$limit = 2;
$data_count = $this->Rooms_model->count_search_results();
$config['base_url'] = base_url().'/index.php/search/index';
$config['total_rows'] = $data_count;
$config['per_page'] = $limit;
$data['results'] = $this->Rooms_model->all_search_results($limit,$offset);
$this->pagination->initialize($config);
//create array to pass to view
$data['pag_links'] = $this->pagination->create_links();
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']))
{
$this->load->view('search/ajax_search_result',$data);
}
else
{
$this->load->view('search/search_view',$data);
}
}
}
MODEL methods
Code:
function count_search_results()
{
//($cat)? $this->db->where('address', $cat) : '' ;
return $this->db->count_all('rooms');
}
/**
* The method - all_search_results - returns all query results from table 'rooms' - it is used by Search controller
*/
function all_search_results($limit, $offset)
{
//($cat)? $this->db->where('category', $cat) : '' ;
$this->db->limit($limit, $offset);
$query = $this->db->get('rooms');
return $query->result();
}
}