Skip to content

Instantly share code, notes, and snippets.

@simonprickett
Created October 23, 2015 18:59
Show Gist options
  • Save simonprickett/b434419d1aefe6e43550 to your computer and use it in GitHub Desktop.
Save simonprickett/b434419d1aefe6e43550 to your computer and use it in GitHub Desktop.
Cordova 5 / iOS 9 Security Blog - index.js
var app = {
initialize: function() {
document.addEventListener('deviceready', this.updateEuroValue, false);
},
updateEuroValue: function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
var euroPrice,
displayText = '',
resultsElement;
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
euroPrice = JSON.parse(xhr.responseText);
displayText = 'US $1 = €' + parseFloat(euroPrice.rates.EUR);
} else {
displayText = 'Error Connecting to API.'
}
resultsElement = document.getElementById('results');
resultsElement.innerHTML = displayText;
document.getElementById('initializing').setAttribute('style', 'display:none;');
resultsElement.setAttribute('style', 'display:block;');
}
};
xhr.open('GET', 'http://api.fixer.io/latest?base=USD&symbols=EUR' , true);
xhr.send();
}
};
app.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment