1
The following script works in part:
<script type="text/javascript">
function ConsUsuario(){
var value = $("#codUser").val();
$.ajax({
type: "GET",
url: "ServiceRestPub/ServiceUsuario.svc/ConsultarRegistroPorCodigo/" + value,
contentType: "application/json",
dataType: "json",
success: function (result) {
alert(result.ConsultarRegistroPorCodigoResult.Nome);
debugger;
var tabela = $("#datagrid");
var rows = "";
tabela.find("tbody td").remove();
var jArrayObject = result;
for (var i = 0; i < result.length; i++) {
var obj = result[i];
alert(obj.Login);
rows += "<tr>";
rows += " <td>" + obj.Codigo + "</td>";
rows += " <td>" + obj.Login + "</td>";
rows += " <td>" + obj.Nome+ "</td>";
rows += " <td> <input type='checkbox' /> </td>";
rows += "</tr>";
}
// tabela.find("tbody").html(rows);
tabela.html('<tbody>' + rows + '</tbody>');
//console.info(result.d);
}
});
}
</script>
when I get on the line go (var i = 0; i < result.length; i++) { to pick up the amount of characters to scan the message object is: Local i : 0 obj : Undefined result : Object and the process stops! How do I scan the object?
I am new to javascript, but I believe the result is: {"Consultarregistroporcodigoresult":{"Code":2,"Code":1,"Login":"ednilson1","Name":"Ednilson","Registration":true,"Password":"123456","Type":"D"}} which is the return of the http query://localhost/ServiceRestPub/ServiceUsuario.svc/ConsultarRegistroPorCodigo/2
– Gleyson Silva
And what property that obj you want to work on?
– Aline
i wanted to read the fields Code, Login and name the play them on the table to be displayed
– Gleyson Silva
In this context you don’t even need the is, if result is a simple object.
– Aline
By @Aline, lack of attention from me, thank you very much worked ok, I do not know if it should be asked here or should be another post, but if the table had more records, how would this be, Lenght work?
– Gleyson Silva
I added the answer. =)
– Aline