function importData() {
var queryURL = "https://gist.githubusercontent.com/heiswayi/7fde241975ed8a80535a/raw/ff1caaeaf62bd6740ab7cafcd61f1215de173379/datatables-data.json";
var xhr = new XMLHttpRequest();
xhr.open('GET', queryURL, true);
// called when the response has arrived
xhr.onload = function(e) {
var jsonResponse = this.response;
// turn the response into a JavaScript object
var users = JSON.parse(jsonResponse);
displayUsersAsATable(users);
}
// in case of error
xhr.onerror = function(err) {
console.log("Error: " + err);
}
// sends the request
xhr.send();
}
function displayUsersAsATable(userList)
{
var table = document.getElementById("generated");
userList.data.forEach(function (item) {
let tableRrow = table.insertRow();
item.forEach(function (cell) {
let tableCell = tableRrow.insertCell();
tableCell.innerHTML = cell;
})
});
}
JS.JSON.FetchingData.PopulateTable.ex7
--------------------------------------
A [Pen](https://codepen.io/Onlyforbopi/pen/QZWVqp) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).
[License](https://codepen.io/Onlyforbopi/pen/QZWVqp/license).