From this url: http://api.open-notify.org/astros.json, I am trying to get the name and craft of each person in space. I can't get it working with my URL, but it works with others... Any ideas?
My code:
<html>
<body>
<table id="personDataTable">
<tr>
<th>Name</th>
<th>Craft</th>
</tr>
</table>
<style>
table {
border: 2px solid #666;
width: 100%;
}
th {
background: #f8f8f8;
font-weight: bold;
padding: 2px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
$.ajax({
url: 'http://api.open-notify.org/astros.json',
type: "get",
dataType: "json",
success: function(data) {
drawTable(data);
}
});
function drawTable(data) {
for (var i = 0; i < data.length; i++) {
drawRow(data[i]);
}
}
function drawRow(rowData) {
var row = $("<tr />")
$("#personDataTable").append(row);
row.append($("<td>" + rowData.people.name + "</td>"));
row.append($("<td>" + rowData.people.craft + "</td>"));
}
</script>
</body>
</html>