0

I would like to perform multiple actions at a time in my dashboard. What I did is as below.

I have dashboard which refreshes using .ajax call every 15 seconds, second ajax call starts after 15 seconds on complete of previous call.

I am using async: true in my method.

Now, there are more other ajax calls events written on that page, my problem is when I click on any other detail report on page at same time of that 15 second call starts.. it keeps me wait and only loads my report when that 15 seconds call finishes.

I dont want to keep in wait to user, when my continuous call starts (15 seconds), I should be able to load any other report and able to call any other ajax methods during that time.

Because, that 15 second call might take 5-10 seconds to get data.. It keeps me in wait.

Below are my code snippet of every 15 seconds.

//Load Live Data event
function GetLiveData() {
    $.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        dataType: 'JSON',
        async: true,
        cache: false,
        data: JSON.stringify({ params }),
        url: url,
        success: function (result) {

            // do soemthing

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        },
        complete: function (xhr, status) {

            //Auto Refresh Data functionality JS


            setTimeOutvar = setTimeout(AutomaticRefreshFunction, RefreshIntervalTime);

            //End of Auto Refresh JS
        }
    });
}

Please suggest, should I use async of MVC 5 or any other alternative?

It is not duplicate of what is suggested.. as I mentioned..

I have one ajax call at every 15 seconds, and that call takes 5-10 seconds to load data, so during that time, If I click on any other button to view data/report - it waits for that regular 15 sec. call. I should not wait and load irrespective to that call.
k-s
  • 2,192
  • 11
  • 39
  • 73
  • Is there another piece of code here, you said you want it to be able to do multiple calls at once whilst this one is running? – Luke Oct 15 '15 at 08:09
  • Possible duplicate of [Multiple ajax calls at same time](http://stackoverflow.com/questions/10150159/multiple-ajax-calls-at-same-time) – Luke Oct 15 '15 at 08:11
  • Hi Coulton, I have one ajax call at every 15 seconds, and that call takes 5-10 seconds to load data, so during that time, If I click on any other button to view data/report - it waits for that regular 15 sec. call. I should not wait and load irrespective to that call. – k-s Oct 15 '15 at 08:53
  • Almost 10 seconds for the execution and the ajax runs every 15 seconds. Basically your app spends all the time refreshing the data. – LeftyX Oct 15 '15 at 09:21
  • yes, every 15 seconds ajax call is getting data on dashboard and it takes 5 seconds appx.. and same time If I click on any detail button .. that again calls other ajax call to get report data.. which keeps in wait for other regular ajax call of 15 sec to finish.. I want to separate them out.. independet calls – k-s Oct 15 '15 at 09:27
  • Just occurred to me that no one has asked. Is this in production or development? In other words, are your running on full IIS or IIS Express within Visual Studio? – Chris Pratt Oct 15 '15 at 13:14

1 Answers1

0

Actually your problem is related to ASP.NET Concurrent Ajax Requests and Session State Blocking.

So,async of MVC5 is not more useful in your scenerio.

So ensure them session that this request can’t update session by readonly or disable value of sessionstate.

paramjeet singh
  • 165
  • 1
  • 10
  • yes, but as I mentioned every 15 seconds one call is ajax call which takes 5-10 second. and at same time I am clicking any button with ajax call which keeps in wait until other call finishes. I want to separate them out. – k-s Oct 15 '15 at 09:25
  • @k-s: You're missing the point. You can run as many simultaneous AJAX calls as you like; there's no limitation there. However, your server has to respond to those, and it's your server that is blocking the second call from completing until the first. I can't say for sure that Paramjeet is right, but it's definitely something to look into. Regardless, you need to look at the server and the code that's running there (which you haven't posted), not your JS. – Chris Pratt Oct 15 '15 at 13:10
  • @k-s: Also Paramjeet is correct about async in MVC not being helpful, at least mostly. Async in MVC is entirely different than async in the sense of AJAX. All it does is allow the thread to be returned to the pool if it's not doing active work, your action is still blocked from returning a response until all the work being done inside is complete. The only thing it might help with is if this is occurring because literally all the threads in the pool have been exhausted, and the second AJAX request is in the queue waiting for an available thread. – Chris Pratt Oct 15 '15 at 13:13
  • Hi Chris, I agree with you comments, but just consider that if I am executing ajax call and during that time I click on another button to another ajax call and return result.. that becomes synchronous .. it should be independent. it should not wait for first call to finish. – k-s Oct 15 '15 at 13:26
  • @k-s Chris also said true in second comment that something to look into server side code.Actually reason in behind to say ASP.NET Concurrent Ajax Requests and Session State Blocking is in Asp.net session block request so that all requests will be process one by one even you use concurrent request with Ajax Async Call. And the solution is disable session on controller you want to hold long-live request.so, if you want to move out from this problem , then create Session less Controller – paramjeet singh Oct 16 '15 at 08:34