Skip to content

Instantly share code, notes, and snippets.

@andrewmatte
Last active October 6, 2016 15:39
Show Gist options
  • Save andrewmatte/5e2b5358b377c2f08c4bf87463c95a48 to your computer and use it in GitHub Desktop.
Save andrewmatte/5e2b5358b377c2f08c4bf87463c95a48 to your computer and use it in GitHub Desktop.
<html>
<head><title>No Framework JavaScript</title>
<style>
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
data from <a href='http://fixer.io/'>http://fixer.io/</a>.
<center>
<h1>Yesterday's Exchange Rates from CAD (Canadian Dollar)</h1>
<div id="content">Loading...</div>
<script>
url = 'http://api.fixer.io/latest?base=CAD';
cont = document.getElementById('content');
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var data = JSON.parse(xhr.responseText);
table = '<table><tr><td>Currency</td><td>Echange rate</td></tr>';
for (var prop in data.rates) {
table += '<tr><td>' + prop + '</td><td>' + data.rates[prop] + '</td></tr>';
};
table +='</table>';
cont.innerHTML = table;
}
}
xhr.open('GET', url, true);
xhr.send(null);
</script>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment