Reputation: 251
I have a call ajax:
JAVASCRIPT
<script type="text/javascript">
$.subscribe('cellselect', function(event, data) {
var cell = event.originalEvent.cellcontent;
$.ajax({
type : "GET",
url : "codcli.action?cliente.codcli="+cell,
dataType : 'json',
success : function(result){
if (result != null && result.length > 0){
$.publish('name');
$.publish('emails');
}
},
error : function(xhr, errmsg) {alert("No values found..!!");}
});
});
</script>
ACTION
<action name="codcli" class="intranet.ConsultarAlumno" method="CargarDatos">
<result type="json">
<param name="root">
cliente
</param>
</result>
</action>
That return the next String JSON
JSON RESULT WITH FIREBUG (OBJECT "cliente")
{"apemat":null,"apepat":null,"cicact":"01","clientedociden":null,"clienteemail":[{"emacli":"[email protected]"},{"emacli":"[email protected]"}],"clientesemestre":null,"clientetelefono":{"contel":0,"escuela":null,"facultad":null,"fechorusucre":null,"fechorusumod":null,"ideusucre":null,"ideusumod":null,"numtel":" 075 225476 975345737","tipotelefono":null},"codant":null,"codcli":"2012534852","codgraaca":null,"codpai":null,"codusu":null,"deuacumor":null,"deuacupen":null,"dirdom":"CALLE JIRON UNION 1274-LA VIRGEN","escuela":{"codesc":"02","desesc":"DERECHO","desescban":null,"desescres":null,"facultad":null,"fechorusucre":null,"fechorusumod":null,"ideusucre":null,"ideusumod":null,"nomdiresc":null,"proproesc":0,"staesc":null,"tipogrado":null},"estcar":null,"estciv":null,"exaadm":null,"facultad":{"codfac":"06","desfac":"DERECHO","desfacres":null,"dirfac":null,"fechorusucre":null,"fechorusumod":null,"ideusucre":null,"ideusumod":null,"nomrep":null,"proprofac":0,"stafac":null,"tipperaca":null,"ubigeo":null},"fechorusucre":null,"fechorusumod":null,"fecnac":null,"ideusucre":null,"ideusumod":null,"moding":null,"modtit":null,"nom":"FABIOLA MARIA","nomcom":"ABADA MUYAGA","numcreacu":null,"numcuracu":null,"numresing":null,"propongen":null,"semegr":null,"semestre":"2","seming":"20131","sex":null,"stacli":null,"tipcli":null,"turmat":"M","ubigeo":{"codpos":null,"codubigeo":null,"depubigeo":"LA LIBERTAD, TRUJILLO, LA VIRGEN","disubigeo":null,"proubigeo":null},"ubigeo2":null,"ultsemact":null,"ultsemmat":null,"valvar":"19\/08\/2013","year":"2013"}
JSP
<p>Here The name</p>
<div id="name"> Atributte "nom" </div>
<p>Here The list of emails</p>
<div id="emails"> Atributte "clienteemail" </div>
QUESTION
What is the best way to work the JSON string to display on the HMTL page the attributes "nom"(name) and "clienteemail"(list of emails) of the JSON String?
Upvotes: 0
Views: 370
Reputation: 50281
Like this ?
....
success : function(cliente){
if (result != null && result.length > 0){
$("#name" ).html(cliente.nom);
$("#emails").html("");
for (var i=0; i < cliente.clienteemail.length; i++) {
$("#emails").append("<br/>" + cliente.clienteemail[i].emacli);
}
}
},
....
Upvotes: 1