In one of the pages from my project, I have this jquery code, which receive two json strings and should add some fields to my form:
<script>
$("document").ready(function(){
var obj_tipo = jQuery.parseJSON( "${lista_tipos}" );
var obj_campo = jQuery.parseJSON( "${lista_campos}" );
var newRow = $('<tr>');
col_1 = '<td> Tipo: </td>';
col_2 = '<td> <select name="tipo"> </select> </td> </tr>';
for(var nome in obj_tipo)
col_2.append('<option value="'+nome+'">'+nome+'</option>');
newRow.append(col_1);
newRow.append(col_2);
$("table.cadastro").append(newRow);
col_3 = '';
for(var nome in obj_campo)
col_3 += '<tr> <td> '+nome+' : </td> <td> <input type="text" name="'+nome+'" value="'+nome+'" size=20 maxlenght=40> </td> <tr>';
$("table.cadastro").append(col_3);
});
</script>
But nothing is being displayed in my page. I check the developer tool from Chrome, and this is being read by the browser:
<script>
$("document").ready(function(){
var obj_tipo = jQuery.parseJSON( "{"Tipo":[{"id":3,"nome":"gerente"},{"id":4,"nome":"supervisor"},{"id":5,"nome":"analista"},{"id":6,"nome":"tecnico"},{"id":7,"nome":"secretaria"},{"id":8,"nome":"seguranca"}]}" );
var obj_campo = jQuery.parseJSON( "{"Key":[{"id":1,"nome":"e-mail"},{"id":2,"nome":"cidade"}]}" );
var newRow = $('<tr>');
col_1 = '<td> Tipo: </td>';
col_2 = '<td> <select name="tipo"> </select> </td> </tr>';
for(var nome in obj_tipo)
col_2.append('<option value="'+nome+'">'+nome+'</option>');
newRow.append(col_1);
newRow.append(col_2);
$("table.cadastro").append(newRow);
col_3 = '';
for(var nome in obj_campo)
col_3 += '<tr> <td> '+nome+' : </td> <td> <input type="text" name="'+nome+'" value="'+nome+'" size=20 maxlenght=40> </td> <tr>';
$("table.cadastro").append(col_3);
});
</script>
Someone can point me What's wrong with this code?
ps.: the full code for this page is this:
the json string is sent to page from the method 'cadastra' of this class: