Chamada AJAX congela o navegador por um tempo enquanto recebe resposta e executa sucesso
Eu estou fazendo uma chamada AJAX para o meu servidor que busca muitos dados. Eu mostro uma imagem de carregamento que gira enquanto a chamada ajax é executada e depois desaparece.
A coisa que eu notei é que todos os navegadores dessa chamada em particular não respondem por cerca de 7 segundos. Dito isto, a imagem de carregamento NÃO está girando como o que planejei enquanto a busca estava ocorrendo.
Eu não sabia se isso era algo que acontecia ou se há uma maneira de fazer isso, de certa forma, porque existe um fork () para fazer 1 coisa, enquanto meu ícone de carregamento ainda gira.
Pensamentos? Idéias?
abaixo está o código como alguém queria ver:
$("div.loadingImage").fadeIn(500);//.show();
setTimeout(function(){
$.ajax({
type: "POST",
url: WEBSERVICE_URL + "/getChildrenFromTelTree",
dataType: "json",
async: true,
contentType: "application/json",
data: JSON.stringify({
"pText": parentText,
"pValue": parentValue,
"pr_id": LOGGED_IN_PR_ID,
"query_input": $("#queryInput").val()
}),
success: function (result, textStatus, jqXHR) {
//alert("winning");
//var childNodes = eval(result["getChildrenFromTelTreeResult"]);
if (result.getChildrenFromTelTreeResult == "") {
alert("No Children");
} else {
var childNodes = JSON.parse(result.getChildrenFromTelTreeResult);
var newChild;
//alert('pText: '+parentText+"\npValue: "+parentValue+"\nPorofileID: "+ LOGGED_IN_PR_ID+"\n\nFilter Input; "+$("#queryInput").val() );
//alert(childNodes.length);
for (var i = 0; i < childNodes.length; i++) {
TV.trackChanges();
newChild = new Telerik.Web.UI.RadTreeNode();
newChild.set_text(childNodes[i].pText);
newChild.set_value(childNodes[i].pValue);
//confirmed that newChild is set to ServerSide through debug and get_expandMode();
parentNode.get_nodes().add(newChild);
TV.commitChanges();
var parts = childNodes[i].pValue.split(",");
if (parts[0] != "{fe_id}" && parts[0] != "{un_fe_id}") {
newChild.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.ServerSide);
}
}
}
//TV.expand();
//recurseStart(TV);
},
error: function (xhr, status, message) {
alert("errrrrror");
}
}).always(function () {
$("div.loadingImage").fadeOut();
});
},500);
Um colega meu percebeu esse problema e sugeriu que eu adicionasse um setTimeout (function () {..}, 500); mas isso não corrige o problema em questão, então provavelmente será removido.