c# – Asynchronous server responses for AJAX calls

Question:

I have an application that at the end of loading a page I make an AJAX request that takes around 20 seconds.

After this request my page continues to work normally so that when I try to make another AJAX request it waits for the first to return the result and then be executed.

Is it possible to execute the second request without having to receive the result of the first?

Front End

$.ajax({
       url: '@Url.Action("NavegarNaEscala")',
       method: 'post',
       cache: false,
       data: { escala: escala, direcao: direcao },
       success: function (data) { 
       },
       error: function () {
           ExibirMensagem(1, "Ocorreu um erro ao navegar na escala.");
       }
  }); 

BackEnd

 public JsonResult NavegarNaEscala(string escala, string direcao)
 {...}

Answer:

I always use Jquery in my AJAX requests:

$(document).ready(function(){
    /*Primeira requisição*/
    $.ajax({...});

    /*Segunda requisição*/
    $.ajax({...});
})

In this case, neither request waits for the other to finish before starting.

$(document).ready(function(){
    /*Primeira requisição*/
    $.ajax({
        success:function(data){
            /*Segunda requisição*/
            $.ajax({...});
        }
    });
})

In this case, the second request will only start after the end (successfully. No communication error with the server or bad formatting of the return file.) of the first.

If you're not doing something like this and yet the second one only starts when the first one finishes, then it could be a typical case of a lock on database resources.

Scroll to Top