I had a couple of instances where I needed some nice, clean AJAX content loaders. Once to slide a page, one to page, and one with no effects.
Here is the code for them… enjoy (p.s. these require you include the JQuery library, also make sure to change any path inside to the path of your loading images)
-
function loadPageFade(strPageToLoad, strWhereToLoadIt) {
-
$.ajax({
-
url: strPageToLoad,
-
beforeSend: function(){
-
$(strWhereToLoadIt).queue( function() {
-
$(this).html(‘<p style="text-align:center;"><img src="/icons/loading_bar.gif" alt="Loading…" /></p>’);
-
$(this).animate({opacity:0}, 500);
-
$(this).dequeue();
-
});
-
},
-
cache: false,
-
success: function(html){
-
$(strWhereToLoadIt).queue( function() {
-
$(this).html(html).animate({opacity:1}, 500);
-
$(this).dequeue();
-
});
-
},
-
error: function(){
-
$(strWhereToLoadIt).queue( function() {
-
$(this).html(‘<div class="err_message">There was an error processing your request.</div>’).animate({opacity:1}, 500);
-
$(this).dequeue();
-
});
-
}
-
});
-
}
-
function loadPageSlide(strPageToLoad, strWhereToLoadIt) {
-
$.ajax({
-
url: strPageToLoad,
-
beforeSend: function(){
-
$(strWhereToLoadIt).slideUp(300);
-
},
-
cache: false,
-
success: function(html){
-
$(strWhereToLoadIt).html(html).slideDown(500);
-
},
-
error: function(){
-
$(strWhereToLoadIt).html(‘<div class="err_message">There was an error processing your request.</div>’).hide().slideDown(500);
-
}
-
});
-
}
-
function loadPage(strPageToLoad, strWhereToLoadIt) {
-
$.ajax({
-
url: strPageToLoad,
-
cache: false,
-
success: function(html){
-
$(strWhereToLoadIt).html(html);
-
},
-
error: function(){
-
$(strWhereToLoadIt).html(‘<div class="err_message">There was an error processing your request.</div>’).hide().fadeIn(1000);
-
}
-
});
-
}
Link to this post!












