jQuery ajax loading wrapper (realy simple :))


/ Published in: jQuery
Save to your folder(s)

And how you do this?


Copy this code and paste it in your HTML
  1. // wrapper function
  2. jQuery.ajaxLoadingWrapper = function(load, loading, ajaxOptions) {
  3. $.ajax($.extend({
  4. beforeSend: function(jqXHR, settings){
  5. $(load).hide();
  6. $(loading).show();
  7. if (ajaxOptions.beforeSend) {
  8. ajaxOptions.beforeSend(jqXHR, settings);
  9. }
  10. },
  11. complete: function(jqXHR, textStatus){
  12. $(loading).hide();
  13. $(load).show();
  14. if (ajaxOptions.complete) {
  15. ajaxOptions.complete(jqXHR, textStatus);
  16. }
  17. }
  18. }, ajaxOptions));
  19. }
  20.  
  21. // usage
  22. $.ajaxLoadingWrapper('#button-ajax-start-selector', '#loading-message-selector', {
  23. url: myUrl,
  24. success: function(data){
  25. // myAjaxSuccess(data);
  26. },
  27. });

URL: ajax-loading-wrapper

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.