Use a loading for ajax requests. This link will help you choose a loading of your choice: https://loading.io/
Here’s an example of how you could put a global loading on your ajax calls.
<div class="load">
<div class="img/load.gif"></div>
</div>
$(document).ajaxStop(function() {
Block(false);
});
$(document).ajaxStart(function() {
Block(true);
});
function Block(status) {
if (status) {
$(".load").show();
} else {
$(".load").hide();
}
}
Call of Ajax
Block(true);
$.ajax({
url: '@Url.Action("", "")',
data: {
id: id
},
type: 'POST',
success: function(response) {
Block(false);
},
error: function(jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status === 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status === 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
console.log(msg);
}
});
This Global Loading would run on any Ajax request made on the correct screen?
– Victor Laio
@Victorlaio
– Netinho Santos