I have an asp.net MVC application, which is using minimal AJAX. I have some pages that require quite a bit of database work before the server responds with the HTML and data.
Depending on what the request was for and how many records a user has, there can be latency of several seconds or more after a user clicks a button or link (could be GET, POST, href, form submission, etc.), where the browser has submitted the request and is spinning its wheels waiting for a response, but has not yet loaded the new page, because the server has not returned anything yet.
Therefore, using document.ready and window.load etc. are not solutions that will work to trigger the loading spinner. I need something that starts as soon as a request to the server is made.
Furthermore, using something along the lines of
$(document).click(function () {//start loading spinner here}
will also not work because there are elements all over the place that can be interacted with but do not make a server request (i.e. bootstrap nav panels, etc.)
I need to implement a loading spinner (or something similar indicating that work is being done and a response is coming) that runs when a request the server has been made, and the browser is "waiting for a response from server".
Update - Things I have tried:
This will trigger the loading spinner plug in loading.js when it's needed, but will also trigger it when it's not, such as when interacting with bootstrap UI elements, etc.
$(document).click(function () {
//Start loading.js anytime a button is clicked
//Show full page LoadingOverlay
$.LoadingOverlay("show");
});
This doesn't work, because once the server returns a response (which is where the long latency is), there only fractions of a second left for the browser to render the HTML and display the view.
$(document).ready(function () {
// Show full page LoadingOverlay
$.LoadingOverlay("show");
});
$(window).on(load, function () {
//Stop loading.js after page loads
$.LoadingOverlay("hide");
});
beforeSend: function(){...}$(document).click(function () {//start loading spinner here}and thought about various ways I could extrapolate this out across different button and link types on all of the pages. That sounds horribly messy though, and want to understand if there is some global event jquery or javascript can bind to for the "waiting for response" state of the browser.