2
I have a function that triggers an ajax request for a route, see:
var getInstituicoesSemUsuario = function(tipo)
{
var resultado = "";
$.ajax(
{
url: "{{path_for('instituicao.sem.responsavel')}}",
data: "tu=" + tipo,
type: "GET",
async: false,
success: function(resposta)
{
resultado = resposta;
}
});
return resultado;
}
With the option async
defined for false
it is possible to get the return of the function getInstituicoesSemUsuario()
, however, Google Chrome issues the following warning:
Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience.
In a nutshell, a synchronous call seems to affect the end-user experience.
However, if I remove the option async
or define it to true
the warning goes away, but, I can’t get the result of the request.
Doubts
- How can I get the result of an asynchronous ajax request?
- Why a synchronous request affects the user’s experience?
- There are scenarios where I can use synchronous requests?
@Thank you Andersoncarloswoss! I was inglezar too :) Out of curiosity I went looking for and found this.
– Sergio