Global Download Notification Using ASP.NET MVC Ajax Calls

I'm interested in providing a general β€œI'm making an ajax call” notification ... it looks like most google services have a little red download notification when it is busy with the call. Is there a way to globally use some events that I can use to show / hide this notification if there is an active call?

We do not use jQuery ajax apis, we use MVC Ajax stuff ... like Ajax.BeginForm or Ajax.ActionLink.

+4
source share
2 answers

I'm not sure why the previous answer was accepted, but you can simply use the LoadingElementId parameter in AjaxOptions by specifying the element identifier in your page with a CSS property to display equal to none.

new AjaxOptions { UpdateTargetId = "somebox", LoadingElementId = "status-waiting" } 

MVC will do the rest of the work for you: when the request is initiated, a DIV will appear, and after completion it will be hidden again. All you have to do is style the window (position, providing a β€œload” image, etc.).

+9
source

If you are using jQuery to do AJAX , you can use one of the lines:

 jQuery.ajax({ url: 'url_to_send_ajax_request_to', beforeSend: function(XMLHttpRequest) { jQuery('#id_of_some_div_that_contains_loading_text').show(); }, complete: function(XMLHttpRequest, textStatus) { jQuery('#id_of_some_div_that_contains_loading_text').hide(); } }); 

The beforeSend handler can be used to display a hidden div containing your loadable text or image, while the full handler will be used to hide it (whether the call is being made or not).

Or if you want to configure it globally for all AJAX requests, you can use the ajaxSetup function:

 jQuery.ajaxSetup({ beforeSend: function(XMLHttpRequest) { jQuery('#id_of_some_div_that_contains_loading_text').show(); }, complete: function(XMLHttpRequest, textStatus) { jQuery('#id_of_some_div_that_contains_loading_text').hide(); } }); 
+7
source

All Articles