JSFiddle - React, Tailwind, and code Playground
by SchmalzyB
JavaScript
var url = 'http://query.yahooapis.com/v1/public/yql?q=';
var symbol = 'PLXS';
var query = encodeURIComponent("select LastTradePriceOnly,Change from yahoo.finance.quotes where symbol in ('" + symbol + "')");
var format = "&format=json&env=http://datatables.org/alltables.env";
var request = new XMLHttpRequest();
request.open('GET',url + query + format, true);
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.responseText);
var currentStockPrice = data.query.results.quote.LastTradePriceOnly;
var change = data.query.results.quote.Change;
alert(currentStockPrice + " (" + change + ")");
console.log(data);
console.log(currentStockPrice);
}
}
};
request.send();
request = null;