I currently have a javascript stock ticker which pulls out live stock data. I really want the company name aswell as the stock acryonm but i am struggling to get this working.
One way which I have done this is by forcing the stock name in text. it seems to work well however the code keeps running over and over duplicating the results. although I'm new to javascript i believe this is related to the i++ and the 3 segments of code.
I have created a jsfiddle to try and understand this better and will hopefully make things clearer.
any help into how to remove the duplication would be greatly appreciated.
https://jsfiddle.net/7o3dgwgq/
var gstock = ["EPA:PIG","LON:AHT","NYSE:URI"];
$(document).ready(function () {
for (var i = 0; i < gstock.length; i++) {
$.getJSON("https://finance.google.com/finance/info?client=ig&q="+gstock[0]+"&callback=?", function (response) {
var stockInfo1 = response[0];
var stockString1 = '<div class="stockWrapper">HAULOTTE:';
var stockName1 = stockInfo1.t;
stockString1 += '<span class="stockSymbol "> ' + stockInfo1.t + ' </span>';
stockString1 += '<span class="stockPrice "> ' + stockInfo1.l + '</span>';
stockString1 += '<span class="stockChange "> ' + stockInfo1.c + '</span>';
stockString1 += '<span> at</span> <span class="stockTime">' + stockInfo1.ltt + '</span>';
stockString1 += '</div>';
$('.haul').prepend(stockString1);
});
}
});
kind regards, Sam