Asynchronous server responses, for AJAX route calls

3

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

After this request my page continues to function normally so when I try to make another AJAX request it waits for the first one to return the result and then to execute.

Can you execute the second request without having to receive the result of the first?

FrontEnd

$.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)
 {...}
    
asked by anonymous 27.08.2014 / 18:55

1 answer

1

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.

$(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 termination (successful, no error of communication with the server or bad formatting of the return file.) of the first.

If you are not doing something like this and even then the second only starts when the first one ends, then it may be a typical case of locking resources in the database.

    
27.08.2014 / 19:19