I'm going to guess that you're using session state.
When you use session state then on the server ASP.NET throttles all requests from the same session to only allow one to execute at a time. I mention this as one of the *many* reasons to not use session:
in addition to session serializing server requests, client side, you are limited to number of active connections. if ajax is using a connection, there may not be a connection free until the ajax (XMLHTTPRequest) request completes. one thing you can do is
abort all pending ajax requests on a navigate event (beforeunload). this wil allow the browser to start another request, but as the server can not detect a closed connection until it writes to the response stream, will not help with session blocking.
bruce (sqlwork.com)
Marked as answer by derricklau on Jan 28, 2013 01:17 PM
derricklau
Member
22 Points
29 Posts
jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 25, 2013 08:37 PM|LINK
function AjaxLoginUpdates(username, proxyUrl) { alert("AjaxLoginUpdates(" + username + ", " + proxyUrl + ") called..."); var currentDate = new Date(); var sendMessage = JSON.stringify({ Type: 0, Username: username, SendTimestamp: currentDate, ServiceUpdateType: -1, CorridorCode: "", Message: "Login" }); var upToAjaxDate = new Date(); var elapsedTime1 = upToAjaxDate.getTime() - currentDate.getTime(); //$.support.cors = true; //alert("Milliseconds to complete AJAX setup: " + elapsedTime1); $.ajaxSetup({ url: proxyUrl, type: "POST", async: true, global: true, timeout: 3600000, contentType: "application/json; charset=utf-8", dataType: "json", data: sendMessage }); $.ajax({ success: function (msg) { alert("ajax.success()."); if (null == msg) { upToAjaxDate = new Date(); elapsedTime1 = upToAjaxDate.getTime() - currentDate.getTime(); alert("Login Updates: Success but no message returned. Elapsed time: " + elapsedTime1 + " ms."); AjaxLoginUpdates(username, proxyUrl); return; } alert("Valid Login/Logoff message returned: [" + JSON.stringify(msg) + "]."); //return; var serverMsg = JSON.stringify(msg); //alert(msg + " string: " + serverMsg); //alert("Message type: [" + msg.Type + "] and ServiceUpdateType: [" + msg.ServiceUpdateType + "]"); var messageStr = String(msg.Message); var usernameStr = String(msg.Username); var loginContainerName = "#_" + msg.ServiceUpdateType + "_LockedBy"; var loginDateTimeName = "#_" + msg.ServiceUpdateType + "_LoggedInDateTime"; var loginDateTime = new Date(msg.LoggedInDateTime); var userCurrentService = $('*:contains(' + usernameStr + ')'); var logoffServiceTypeName = $(userCurrentService).attr('ID'); var substr = logoffServiceTypeName.split('_'); var logoffServiceType = substr[1]; var logoffContainerName = "#_" + logoffServiceType + "_LockedBy"; var logoffDateTimeName = "#_" + logoffServiceType + "_LoggedInDateTime"; if (msg.Type == 0) { alert("Login Updates: " + usernameStr + " has logged into "); $(logoffContainerName).html(""); $(logoffDateTimeName).html(""); $(loginContainerName).html(usernameStr); $(loginDateTimeName).html(loginDateTime.toLocaleString("YYYY-MM-DD HH:mm")); } else if (msg.Type == 1) { alert("Login Updates: " + usernameStr + " has logged out of "); $(loginContainerName).html(""); $(loginDateTimeName).html(""); } AjaxLoginUpdates(username, proxyUrl); return; }, error: function (jqXHR, textStatus, errorThrown) { alert("AJAX error!"); AjaxLoginUpdates(username, proxyUrl); return; } // complete: function () { //alert("AjaxLoginUpdates(): Complete event."); //loginUpdates.abort(); //if (abortLoginUpdates == false) { // AjaxLoginUpdates(username, proxyUrl); //} //return; // } }); }I then start the page and it waits until the $.ajax() call has timed out before the Page_Load() method completes.
Also, when I try to navigate to another page, it hangs until the $.ajax() call has completed.
Why? How do I stop this? I want my $.ajax() call to abort immediately if I click on a link to leave the current page.
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 26, 2013 12:11 AM|LINK
I'm going to guess that you're using session state.
When you use session state then on the server ASP.NET throttles all requests from the same session to only allow one to execute at a time. I mention this as one of the *many* reasons to not use session:
http://brockallen.com/2012/04/07/think-twice-about-using-session-state/
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
bruce (sqlwo...
All-Star
36894 Points
5452 Posts
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 26, 2013 10:39 PM|LINK
in addition to session serializing server requests, client side, you are limited to number of active connections. if ajax is using a connection, there may not be a connection free until the ajax (XMLHTTPRequest) request completes. one thing you can do is abort all pending ajax requests on a navigate event (beforeunload). this wil allow the browser to start another request, but as the server can not detect a closed connection until it writes to the response stream, will not help with session blocking.
derricklau
Member
22 Points
29 Posts
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 27, 2013 09:17 PM|LINK
Not really using session state. Is there any other possibility for this behaviour?
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 27, 2013 09:24 PM|LINK
So you've explicitly disabled session, or you're using it? Session has a way of creeping into your app... TempData perhaps?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
derricklau
Member
22 Points
29 Posts
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 27, 2013 10:18 PM|LINK
Thanks for responding so quickly. Your willingness to help is greatly appreciated.
I haven't explicitly disabled session state...that will be my next step...
I'm still on old ASP.NET 4.0, no MVC yet, so that rules out TempData, correct?
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 27, 2013 11:51 PM|LINK
Yep, TempData is a MVC thing. So go ahead and disable it so we're sure it's not session state.
The other suggestion I'd make is to reduce your code to the smallest/simplest amount of code to repoduce the problem.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
derricklau
Member
22 Points
29 Posts
Re: jQuery $.ajax() call is hanging and I cannot go to another page until the call ends.
Jan 28, 2013 01:18 PM|LINK
Explicitly disabled session state and that resolved everything. Hmmm...got to get off using Session state then.
Special thanks to BrockAllen and Bruce for their quick responses.