Created
July 13, 2016 19:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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