Skip to content

Instantly share code, notes, and snippets.

@webarthur
Created July 13, 2016 19:17
Show Gist options
  • Save webarthur/afd6a10c7b91ddb2774f022832c8234b to your computer and use it in GitHub Desktop.
Save webarthur/afd6a10c7b91ddb2774f022832c8234b to your computer and use it in GitHub Desktop.
Cotação do dolar, euro, real e outras moedas em XML ou JSON com jQuery/Javascript
// URL com a Query do YQL
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22USDBRL%22&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
// Obtem e trata os dados em JSON
$.getJSON( url, function( data ) {
// Agrupa os dados em HTML
try {
var indices = '<p><strong>DOLAR</strong> R$ '+data.query.results.rate[0].Rate+'</p>';
} catch(err) {
var indices = err.message;
}
// Mostra a cotação do dolar na tag <div id="info"></div>
$('#info').html(indices);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment