Reputation: 7515
I am trying twitter pagination in using JQuery. I have a search page (contains form) which will query the database and display it in the search results page.
When I am trying to hit the div tag (More button in the below page) in the below code, it should append only the data to #results
instead the entire page is loading along with #content
the appended data which looks same page overlapping one over the other. The logic of loading the data from the database and loading appropriate results when I hit More
button. The only problem is displaying the results properly
Here is my code
<body>
<?php $this->load->view('includes/topbar'); ?>
<?php $this->load->view('includes/menu'); ?>
<?php $this->load->view('includes/left'); ?>
<div id="contentwrap">
<div id="content">
<div id="results">
<?php
foreach($this->data['latest_messages'] as $message)
{
echo $message->uacc_email . ' - ' . '<br />';
}
?>
</div>
<div id="more_button">
More
</div>
</div>
</div>
<?php $this->load->view('includes/right'); ?>
<?php $this->load->view('includes/foot'); ?>
</body>
Here is the code for my jquery in <head>
section. The auth_public/get_results/
will get the results from database.
<script type="text/javascript">
$(document).ready(function(){
var num_messages = <?=$num_messages?>;
var loaded_messages = 0;
$("#more_button").click(function(){
loaded_messages += 10;
$.get("<?php echo $base_url;?>" + "auth_public/get_results/" + loaded_messages, function(data){
$("#results").append(data);
});
if(loaded_messages >= num_messages - 10)
{
$("#more_button").hide();
//alert('hide');
}
})
})
</script>
I have tried using span. But no luck the behavior is same. Any one help on this?
Upvotes: 0
Views: 1843
Reputation: 111
your problem with the get_results
, i guess it returns output as html instead of json output as "jammykam" mentioned
go to auth_public
look for the function get_results
and replace the output line that should look like this $this->load view($your_view,$data);
or this $this->parser->parse($your_view,$data);
with echo json_encode($data);
Upvotes: 2