0
I cannot play the result of the ajax query inside a table. The result is an array (result = Object {Query categoriesresult: Array(6)})
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1">
<div class="jumbotron">
<input type="text" id="codUser"/>
<button onclick="ConsUsuario(); return false;">Consulta Usuario</button>
</div>
<div><table id="datagrid"></table></div>
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ConsUsuario(){
$.ajax({
type: "GET",
url: "http://food-fast-com.web27.redehost.net/CategoriaService.svc/ConsultarTodosCategorias",
contentType: "application/json",
dataType: "json",
success: function (result) {//result = Object {ConsultarTodosCategoriasResult: Array(6)}
debugger;
var tabela = $("#datagrid");
var rows = "";
tabela.find("tbody td").remove();
var myData = ConsultarTodosCategoriasResult;
for (var i = 0; i < myData.length; i++) {
var obj = myData[i];
rows += "<tr>";
rows += " <td>" + result.ConsultarTodosCategoriasResult.Descricao + "</td>";
rows += "</tr>";
}
tabela.html('<tbody>' + rows + '</tbody>');
}
});
}
</script>
when assigning the result to variable (var myData = Query categoriesresult;) of the following error: Uncaught Referenceerror: Query categoriesresult is not defined
Query categoriesresult has not been defined, i.e., it must be in result, from a console.log(result) and see where you find what you need
– Felipe Duarte
the result is an object array: Object {Query categoriesresult: Array(6)}Query categoriesresult: Array(6)0: Objectcategoria_id: 1Description: "PIZZAS"Filial_id: 1Id: null__proto__: Object1: Object2: Object3: Object4: Object5: Objectcategoria_id: 6Description: "HAMBURGUER"Filial_id: 1Id: null__proto__: Objectlength: 6__proto__: Array(0)proto: Object
– Gleyson Silva
I got Felipe, changed as follows: var myData = result.Query
– Gleyson Silva
that’s right haha
– Felipe Duarte