0
I would like the XML data to be displayed in a common HTML table with TR
and TD
, because with the code I’m using the information gets confused.
Follow the code I used:
$(function(){
$.ajax({
url : "livraria.xml",
success : function(xml){
$(xml).find("livro").each(function() {
$("#tabela").append(
"Titulo: " +"<br/>"+
"</td></tr>"+ $(this).attr("id") + "-" + "<br/>"+
$(this).text()+"<br>"
);
});
},
error: function(){
alert("Mensagem de erro.");
}
});
});
Can you give an example of the XML you are receiving? what does
console.log(typeof xml, xml);
within thatsuccess
?– Sergio
Your code is confused, you’re doing
append
intable
without creating a line (tr
). It should be something like this:$("#tabela").append("<tr><td>" + $(this).text() + "</td></tr>");
– Ricardo Pontual
@Ricardopunctual I wanted the html page to look more or less like the w3schools http://www.w3schools.com/xml/xml_usedfor.asp. I edited the code more or less like you said: $("#table"). append("<tr><td>" + $(this).attr("id") + "<br/>"+ $(this). text()+"</td></tr>"); but the html looks like this: http://i.imgur.com/Sra44lg.png
– matheus.m94