Return to Snippet

Revision: 51224
at September 18, 2011 05:09 by graceman9


Updated Code
// wrapper function
jQuery.ajaxLoadingWrapper = function(load, loading, ajaxOptions) {
  $.ajax($.extend({
    beforeSend: function(jqXHR, settings){
      $(load).hide();
      $(loading).show();
      if (ajaxOptions.beforeSend) {
        ajaxOptions.beforeSend(jqXHR, settings);
      }
    },
    complete: function(jqXHR, textStatus){
      $(loading).hide();
      $(load).show();
      if (ajaxOptions.complete) {
        ajaxOptions.complete(jqXHR, textStatus);
      }
    }
  }, ajaxOptions));
}

// usage
$.ajaxLoadingWrapper('#button-ajax-start-selector', '#loading-message-selector', {
  url: myUrl,
  success: function(data){
    // myAjaxSuccess(data);
  },
});

Revision: 51223
at September 18, 2011 05:07 by graceman9


Initial Code
// wrapper function

jQuery.ajaxLoadingWrapper = function(load, loading, ajaxOptions) {

  $.ajax($.extend({

    beforeSend: function(jqXHR, settings){

      $(load).hide();

      $(loading).show();

      if (ajaxOptions.beforeSend) {

        ajaxOptions.beforeSend(jqXHR, settings);

      }

    },

    complete: function(jqXHR, textStatus){

      $(loading).hide();

      $(load).show();

      if (ajaxOptions.complete) {

        ajaxOptions.complete(jqXHR, textStatus);

      }

    }

  }, ajaxOptions));

}



// usage

$.ajaxLoadingWrapper('#button-ajax-start-selector', '#loading-message-selector', {

  url: myUrl,

  success: function(data){

    // myAjaxSuccess(data);

  },

});

Initial URL
ajax-loading-wrapper

Initial Description
And how you do this?

Initial Title
jQuery ajax loading wrapper (realy simple :))

Initial Tags
ajax

Initial Language
jQuery