Colegas, tô precisando muito da ajuda de vcs, seguinte :
Tenho uma função em AJAX que vai no SERVLET e pesquisa no BD um cadastro de cidades e retorna utilizando JSON, mas não estou conseguindo montar a tabela no JS, vejam meus códigos :
Retorno Servlet (JSON) :
responseString= "
{"cidades": [
{"codigo":"922","descricao":"","regional":"1"},
{"codigo":"921","descricao":"","regional":"1"},
{"codigo":"874","descricao":"","regional":"1"},
{"codigo":"905","descricao":"345546","regional":"1"},
{"codigo":"2","descricao":"ABAETE","regional":"5"},
Minha tabela lá no JSP :
<table width="60%" align="center" cellspacing="0">
<c:forEach items="${requestScope.cidade}" var="cidade" varStatus='s'>
<tr>
<c:choose>
<c:when test='${s.count % 2 == 0}'>
<tr bgcolor='#aaaaaa'>
</c:when>
<c:otherwise>
<tr bgcolor='#dddddd'>
</c:otherwise>
</c:choose>
<td width="60%" class="style3"><c:out value="${cidade.descricao}"/></td>
<td width="30%" class="style3">
<c:choose>
<c:when test="${cidade.regional==1}">LESTE</c:when>
<c:when test="${cidade.regional==2}">MANTIQUEIRA</c:when>
<c:when test="${cidade.regional==3}">METALÚRGICA</c:when>
<c:when test="${cidade.regional==4}">NORTE</c:when>
<c:when test="${cidade.regional==5}">OESTE</c:when>
<c:when test="${cidade.regional==6}">VALE DO AÇO</c:when>
<c:when test="${cidade.regional==7}">TRIÂNGULO</c:when>
<c:when test="${cidade.regional==8}">OUTRAS BASES</c:when>
</c:choose>
</td>
<td width="10%"><input type="image" src="${pageContext.request.contextPath}/images/view16.gif" onclick="enviar('ler','<c:out value="${cidade.id}"/>','<c:out value="${cidade.registro}"/>')"/></td>
</tr>
</c:forEach>
</table>
Meu JS de retorno :
function mostraCidades(){
if (req.readyState == 4){
if (req.status == 200){
preencheCidade(req);
if (retorno=="Erro"){
alert(retorno);
}
}
}
}
function preencheCidade(req){
jsonData = req.responseText;
var myJSONObject = eval('(' + jsonData + ')');
for (i=0;i<myJSONObject.cidades.length;i++){
[b]<---------- AQUI ESTOU AGARRADO, NÃO CONSIGO MONTAR----->[/b]
}
}
Alguem poderia me dar uma luz ?
Vimieiro
