1

So ASP.NET will not make new Ajax call if other ajax call is running until it returns.

What I am trying to do is to abort previous ajax call and make new one. So here is my code:

var firstAjaxId = null;
object1.onclick=function(){
   firstAjaxId = $.post("/Controller/Method", data, function(response) {
       firstAjaxId = null;
   }
};

object2.onclick=function(){
   //cancel first ajax so we don't wait it's done
   if(firstAjaxId = null){
      firstAjaxId.abort();
   }
   //make new ajax call
   $.post("/Controller/Method2", data, function(response) {
       //do something
   }
};

So what is happening that if first ajax call is running when I try to make the second ajax call, the second one will wait first to be done. As you can see in the code I tried to abort first ajax before making the second one but this doesn't help. The second will still wait until server unlock session. This abort only aborts client side so it doesn't wait for response, but server will still keep session locked. So is there any way to make this working, to cancel first ajax and release session so I can make new one.

Method called in the first ajax only read from session, it doesn't update it. Method called in the second ajax will read and update session.

UPDATE:

Have to say that as I can see ASP.NET lock session on ajax call and it doesn't allow making another ajax call until first one is done and unlock the session.

Explained well in this quesion:

Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

Community
  • 1
  • 1
carpics
  • 2,272
  • 4
  • 28
  • 56
  • Try setting async to false in your ajax call – Karthikeyan May 30 '16 at 11:47
  • Possible duplicate of [Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?](http://stackoverflow.com/questions/4428413/why-would-multiple-simultaneous-ajax-calls-to-the-same-asp-net-mvc-action-cause) – Lajos Arpad May 30 '16 at 13:50

0 Answers0