I am trying to get a simple exchange rate from USD to MXN using yahoo api but Im not getting anything back, is this just a CORS issue again or am I accessing the property incorrectly?
var exchangeRateURL = "*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDMXN%22%29&env=store://datatables/alltableswithkeys";
//Get current USD->MXN exchange rate
$.getJSON(exchangeRateURL, function(data)
{
priceInMXN = data.query.results.rate.Rate;
document.write(priceInMXN);
});
Thanks in advance!
I am trying to get a simple exchange rate from USD to MXN using yahoo api but Im not getting anything back, is this just a CORS issue again or am I accessing the property incorrectly?
var exchangeRateURL = "http://query.yahooapis./v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDMXN%22%29&env=store://datatables/alltableswithkeys";
//Get current USD->MXN exchange rate
$.getJSON(exchangeRateURL, function(data)
{
priceInMXN = data.query.results.rate.Rate;
document.write(priceInMXN);
});
Thanks in advance!
Share Improve this question asked Dec 3, 2015 at 4:48 Noah-1Noah-1 3961 gold badge5 silver badges21 bronze badges 1- 1 What does your console say? Also that endpoint appear to provide XML, not JSON. – Marty Commented Dec 3, 2015 at 4:51
2 Answers
Reset to default 3Pass a param to return JSON (&format=json):
var exchangeRateURL = "http://query.yahooapis./v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDMXN%22%29&env=store://datatables/alltableswithkeys&format=json"
$.getJSON(exchangeRateURL, function(data) {
console.log(data.query.results.rate.Rate);
});
You're fetching XML, not JSON. Something like this will work:
$.get(exchangeRateURL, function(data) {
console.log($(data).find('Rate').text());
});