I trying to learn jquery as im new to it. here I have made a request to this example API and got an array of object that i have to list in to the table. However, im stuck on how to sort in to the table? please help me out
I have my html
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td data-column="ID" id="_id"></td>
<td data-column="Name" id="_name"></td>
<td data-column="Age" id="_age"></td>
<td data-column="Salay" id="_salay"></td>
</tr>
</tbody>
</table>
and my script
$(document).ready(function(){
$("button").click(function(){
$.get("http://dummy.restapiexample.com/api/v1/employees", function(data, status){
if(data.status == "success"){
let listData = JSON.parse(data.data)
console.log(listData);
}
});
});
});
here i got an error as below:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at Function.parse [as parseJSON] ()
2
Answers
Basically you are again parsing a JSON array which is return from API.
Your API is returning the below data.
for Example