I am currently trying to learn RESTful API's and implementing them into use case and one of the things I am trying to do is to load the url with the json payload from one server into a separate web server to display on a table the data. I am not too familiar with this so I am trying to find out the best way to do this.
I am using this API to post to a page which is domain.com/todos
https://github.com/corylanou/tns-restful-json-api
And then I am attempting to use this to print it out to a table https://github.com/sam-suresh/JSON-URL-to-HTML-Table
but it doesn't look like it is working. I put it all into a single index file and it shows it hitting my api on the console but I am not showing any output in the table.
<html>
<table id="personDataTable">
<tr>
<th>id</th>
<th>name</th>
<th>due</th>
</tr>
</table>
<style>
table {
border: 2px solid #666;
width: 100%;
}
th {
background: #f8f8f8;
font-weight: bold;
padding: 2px;
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$.ajax({
url: 'http://my-website-domain.com/todos',
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.id + "</td>"));
row.append($("<td>" + rowData.name + "</td>"));
row.append($("<td>" + rowData.due + "</td>"));
}
</script>
</html>
And this is what it shows on the /todos page
[{"id":1,"name":"Write presentation","completed":false,"due":"0001-01-01T00:00:00Z"},{"id":2,"name":"Host meetup","completed":false,"due":"0001-01-01T00:00:00Z"},{"id":3,"name":"New Todo","completed":false,"due":"0001-01-01T00:00:00Z"}
data?console.log(data)indrawTablefunction for example and provide an outputdataofsuccess: function(data)is a json object?