The website is build with Codeigniter MVC framework.
I have a page that is taking longer to load (about 20 seconds) due to the nature of the query and the large database size.
Is there a way I can show a 'Loading...' gif image as the view is getting开发者_JS百科 loaded? Looking for an example using codeigniter.
Thanks
Typcial ajax loaders are accomplished with javascript. Basically, the first thing your click handler does is show the animated gif then executes the javascript command to load the new content into the page. There's really no codeigniter involved.
Here's a link to a page exhibiting a way to do this with jquery.
To summarize:
$(document).ready(function(){
$('.your_button').click(function(){
//show your loader gif (recommend loading and hiding with css
$('#new_content img.ajax_loader').show();
//where you'll load the page
$.post(href,{data},function(new_data){
$('#new_content').html(new_data);
});
});
Use jQuery BlockUI plugin
Here's an idea of how to do it (not entirely) with Javascript:
- Register the query that the user would like executed
- Place the query in a queue in the database with the status: pending
- Redirect the user to a page with your loading gif on it, constantly polling another page with AJAX capable of checking the status of the query in your queue returning a URL to the query results when it's complete
- Have a separate program work it's way through the queue, setting the status of the query to complete and caching the results in the table
精彩评论