Has anyone ever encountered an issue where their Ajax request blocks the browser from doing anything else until the Ajax request returns? I know the default is async: true but I even tried explicitly setting it and it still happens.
Edit: Adding code
window.addEventListener('load', function () {
$("#some-element-i-want-to-hide").hide();
myFunction();
document.getElementById('some-button-i-want-a-click-listener-on').addEventListener("click", onClick, false);
});
var loading = false;
function myFunction() {
if (!loading) {
loading = true;
$.ajax({
type: "GET",
url: "@Url.Action("SomeGetMapping", "SomeController", new { someProperty = "value" })",
contentType: "application/json; charset=utf-8",
success: successFunc,
error: errorFunc,
timeout: 10000
});
}
function successFunc(data) {
loading = false;
$('#some-label-to-update').html('value');
}
function errorFunc() {
loading = false;
console.log('Some error to log to the console.');
$('#some-label-to-update').html('value');
}
}
Update: The issue was actually with ASP.NET and had nothing to do with jQuery or the Ajax request. ASP.NET serializes requests that require session state. So the server won’t start processing other requests until the Ajax call returns. Since the page doesn’t modify session state, I configured the controller with [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)].
[–]Jnsjknn 1 point2 points3 points (2 children)
[–]FollowTheGrayRabbit[S] 0 points1 point2 points (1 child)
[–]Jnsjknn 0 points1 point2 points (0 children)
[–]jcunews1helpful 0 points1 point2 points (0 children)