2
Good afternoon, you guys,
I have the following AJAX request:
$(document).ready(function () {
$.ajax({
url: "/membros.aspx/populaGridMembros",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
populaTabela(result);
},
error: function() {
alert("Ocorreu um erro ao carregar os dados.");
}
});
});
The populaTable method takes the result of the populaGridMembers function and inserts it into a table on the page.
The problem is that when I run this code on the page, there is no error in the AJAX request, but it does not enter the Success parameter. In the firefox debugging I discovered that after it ran all this javascript code, ie during the debug step by all parameters of the $.ajax function(url, type, dataType, contenttype, Success and error the $.ajax function returns the values returned by the populated functionGridMembers of the url and displays a window with the following information:
Can someone help me? Thanks in advance!!!
Follows the code of the populaTable function:
function populaTabela(response) {
var data = JSON.parse(response);
for (var j in data) {
out += "<tr><td>" + data[j].NOME + "</td><td>" +
"</td><td>" + data[j].SOBRENOME + "</td><td>" +
"</td><td>" + data[j].RG + "</td><td>" +
"</td><td>" + data[j].CPF + "</td><td></tr>";
j++;
}
}
You can enter the function code
populaTabela()
?– Sergio
Good afternoon Sergio, thank you for evaluating my question. I added the function code to the question.
– Alexandre Nascimento
What is the HTTP code that
/membros.aspx/populaGridMembros
is returning?– André Ribeiro
What
repsonse
contains? Useconsole.log
or Inspecione the answer directly in the browser.– Vinícius Gobbo A. de Oliveira
@Alexandrenaissance once you’re using
dataType: "json",
it seems to me that this line is redundant:var data = JSON.parse(response);
can doconsole.log(response);
at the beginning of this function? what happens on the console?– Sergio
Not only redundant as @Sergio said, but perhaps the cause of the problem.
– bfavaretto
I also thought and removed this line of code, the problem is that it doesn’t even enter Success routine. When it arrives in Success the value that the function /members.aspx/populaGridMembers should return is not yet returned, it is as if the Sponse had not yet occurred, so when it arrives in Success the Function result parameter is with Undefined value, only after it passes the error and finishes all the parameters is that the $.ajax function returns the values in responseText.
– Alexandre Nascimento