Tuesday, 26 May 2020

Bring Data to HTML using XMLHttpRequest

<!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>

No comments:

Setup Windows Local Account without the Internet

During the Windows setup,  On the WiFi screen, press SHIFT + F10  or  FN + SHIFT + F10  This will open the command prompt window with admini...