Reputation: 1
Please help me. How to add for this script error info (eg no page)? I would like to view this information in loader.
var AjaxContent = function(){
var container_div = '';
var content_div = '';
return {
getContent : function(url){
$(container_div).animate({opacity:0}, //Turn the opacity to 0
function(){ // the callback, loads the content with ajax
$(container_div).find("#loading").show();
$(container_div).load(url+" "+content_div, //only loads the selected portion
function(){
$(container_div).animate({opacity:1}); //and finally bring back the opacity back to 1
$(container_div).find("#loading").hide();
}
);
});
},
ajaxify_links: function(elements){
$(elements).click(function(){
$('#loading').show();
AjaxContent.getContent(this.href);
return false; //prevents the link from beign followed
});
},
init: function(params){ //sets the initial parameters
container_div = params.containerDiv;
content_div = params.contentDiv;
return this; //returns the object in order to make it chainable
}
}
}()
/* Ajax Content Loading Controls */
$(function(){
AjaxContent.init({containerDiv:".content_background",contentDiv:"#text"}).ajaxify_links("#nav a");
});`
Upvotes: 0
Views: 101
Reputation: 8406
look into http://api.jquery.com/ajaxError/.. first, add an element to which you'll add your error message content
<div id="errors"></div>
then add some javascript to catch Ajax Errors and write to this div
$( "#errors" ).ajaxError(function(e, jqxhr, settings, exception) {
$(this).text("your error message");
});
or if you don't want to bind the ajaxError
event to a div, use this code:
$(document).ajaxError(function(e, jqxhr, settings, exception) {
console.log("your error message");
});
or to use your code exactly, try this:
var AjaxContent = function(){
var container_div = '';
var content_div = '';
return {
getContent : function(url){
$(container_div).animate({opacity:0}, //Turn the opacity to 0
function(){ // the callback, loads the content with ajax
$(container_div).find("#loading").show();
$(container_div).load(url+" "+content_div, //only loads the selected portion
function(){
$(container_div).animate({opacity:1}); //and finally bring back the opacity back to 1
$(container_div).find("#loading").hide();
}
);
});
},
ajaxify_links: function(elements){
$(elements).click(function(){
$('#loading').show();
AjaxContent.getContent(this.href);
return false; //prevents the link from beign followed
});
},
init: function(params){ //sets the initial parameters
container_div = params.containerDiv;
content_div = params.contentDiv;
return this; //returns the object in order to make it chainable
}
}
}()
/* Ajax Content Loading Controls */
$(function(){
$(document).ajaxError(function(e, jqxhr, settings, exception) {
console.log("your error message");
});
AjaxContent.init({containerDiv:".content_background",contentDiv:"#text"}).ajaxify_links("#nav a");
});
Upvotes: 2