Im a total noob to html, css, javascript, and programming altogether. Please bear with me.
Im trying to populate my table using jquery. The data will be coming from an xml file.
football_player.xml:
<?xml version="1.0" encoding="UTF-8"?>
<football_player>
<name>Cristiano Ronaldo</name>
<club>Real Madrid</club>
<number>7</number>
<country>Portugal </country>
<name>Fernando Torres </name>
<club>Chelsea </club>
<number>9</number>
<country>Spain</country>
<name>Iker Casillas</name>
<club>Real Madrid </club>
<number>1</number>
<country>Spain</country>
<name>David Beckham</name>
<club>Los Angeles Galaxy</club>
<number>23</number>
<country>England</country>
</football_player>
My html table:
<table>
<thead>
<tr>
<th>Name</th>
<th>Club</th>
<th>Number</th>
<th>Country</th>
</tr>
</thead>
<tbody>
</tbody>
</tfoot>
</tfoot>
</table>
My javascript/jquery script:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "football_player.xml",
dataType: "xml",
success: function(xml) {
$(xml).find("football_player").each(function () {
$("table tbody").append("<tr>");
$("table tbody").append("<td>" + $(this).find("name").text() + "</td>");
$("table tbody").append("<td>" + $(this).find("club").text() + "</td>");
$("table tbody").append("<td>" + $(this).find("number").text() + "</td>");
$("table tbody").append("<td>" + $(this).find("country").text() + "</td>");
$("table tbody").append("</tr>");
});
}
});
});
I swear Im really a noob. I don’t have any idea of what Im doing. Please help. I really want to learn. Thanks in advance.
The sample XML:
And the HTML & jquery.
you can go through the example and you will get idea about the same