Quantcast
Channel: jQuery – Michael Grosser, the Blog
Viewing all articles
Browse latest Browse all 11

jQuery .load extension to indicate loading and errors

$
0
0
  // show loading animation and errors inside the container that is being replaced
  // http://grosser.it/2012/06/21/jquery-load-extension-to-indicate-loading-and-errors
  $.fn.responsiveLoad = function(url, callback){
    var loading = 'Loading';
    var $container = $(this);
    $container.html(loading).load(url, function(response, status, xhr){
      if (status == "error") {
        $container.html("Error:" + xhr.status + " " + xhr.statusText);
      } else {
        if(callback) callback(response, status, xhr);
      }
    });
  };

Tagged: Javascript, jQuery, JS

Viewing all articles
Browse latest Browse all 11

Trending Articles