<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
function GetData() {
var req = new XMLHttpRequest();
req.open ('GET','https://jsonplaceholder.typicode.com/posts');
req.onload = function () {
var data = JSON.parse(req.responseText);
RenderHtml (data);
}
req.send();
}
function RenderHtml(data) {
console.log (data)
var dt = "";
for (i=0; i<data.length; i++) {
dt += "<p>" + data[i].title + "</p>";
}
document.getElementById ('dataTable').innerHTML = dt;
}
</script>
</head>
<body>
<div id="dataTable">Nothing yet...</div>
<button onclick="GetData()">Get Data</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
function GetData() {
var req = new XMLHttpRequest();
req.open ('GET','https://jsonplaceholder.typicode.com/posts');
req.onload = function () {
var data = JSON.parse(req.responseText);
RenderHtml (data);
}
req.send();
}
function RenderHtml(data) {
console.log (data)
var dt = "";
for (i=0; i<data.length; i++) {
dt += "<p>" + data[i].title + "</p>";
}
document.getElementById ('dataTable').innerHTML = dt;
}
</script>
</head>
<body>
<div id="dataTable">Nothing yet...</div>
<button onclick="GetData()">Get Data</button>
</body>
</html>
No comments:
Post a Comment