How to stop Jquery Ajax “pages unresponsive you can wait for it to become responsive or exit the page” popup error in chrome browser

I have popup issue with Google Chrome browser.
I am using .Net MVC ajax method, The ajax call to server(controller) side and it take long time execution (50 sec to 2 mins and above).
This time Chrome browser shows "pages unresponsive, you can wait for it to become responsive or exit the page" error popup message.
I'm searching many website.Still i didn't get any solution regarding this.

some website says:
async: false change to async: true

async: true change means its working fine. But async: true means first ajax call execute (success function) response before going to next statement.
Next next statement execute after finally comes first ajax success function response.
so I need first ajax call execute and when (success function) response return after goto next statement and how to stop “pages unresponsive you can wait for it to become responsive or exit the page” popup window error in chrome browser.
enter image description here ajax Code:

$.ajax({
        url: "../Report/MonthlyOrder",
        type: "POST",
        async: false,
        //async: true,
        dataType="json",
        data:{FromDate:fromDate,ToDate:toDate},
        success: function (response) {
             //.......
        }
    });

    //Next Staement
    //function 1
    //function 2
    
    

Please help me ...! Thanks in Advance....

Upvotes: 0

Views: 3253

Answers (1)

AKX
AKX

Reputation: 169407

Unfortunately you'll just have to refactor your code to be able to use async: true, i.e. put that "next statement" and so on inside success, or maybe use the promise-like interface:

$.ajax({
  url: "../Report/MonthlyOrder",
  type: "POST",
  async: true,
  dataType: "json",
  data: { FromDate: fromDate, ToDate: toDate },
}).done((response) => {
  // next statement...
});

If you're in an environment where you can use async/await and real promises, this could be made easier still.

Upvotes: 0

Related Questions