Skip to content

Instantly share code, notes, and snippets.

@eliandoran
Created June 4, 2021 11:14
Show Gist options
  • Save eliandoran/161a6a020ebb602d479ce2558cbdec67 to your computer and use it in GitHub Desktop.
Save eliandoran/161a6a020ebb602d479ce2558cbdec67 to your computer and use it in GitHub Desktop.
<!DOCTYPE
<html>
<body>
<label>Curs valutar</label>
<input id="exchange-rate" type="text" disabled />
<button id="update-button">Update</button>
<script>
var URL = "http://www.infovalutar.ro/bnr/azi/eur";
var updateButtonEl = document.getElementById("update-button");
var exchangeRateTextEl = document.getElementById("exchange-rate");
updateButtonEl.onclick = function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState !== 4) {
// Not yet ready.
return;
}
if (this.status === 200) {
const responseText = xhttp.responseText;
exchangeRateTextEl.value = responseText;
} else {
alert("Eroare la preluarea datelor.");
}
};
xhttp.open("GET", URL, true);
xhttp.send();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment