I am trying to get the stock details from google finance using the following code.
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js"></script>
<script>
var gstock=["INDEXBOM:SENSEX","SHA:000001"];
$(document).ready(function(){
for( var i=0;i<gstock.length;i++){
$.getJSON("https://finance.google.com/finance/info?client=ig&q=".gstock[i]."&callback=?",function(response){
var stockInfo = response[0];
var stockString ='<div class="stockWrapper">STOCK:';
stockString +='<span class="stockSymbol">'+stockInfo.t+'</span>';
stockString +='<span class="stockPrice">'+stockInfo.l+'</span>';
stockString +='<span class="stockChange">'+stockInfo.c+'</span>';
stockString +='<span>at</span> <span class="stockTime">'+stockInfo.ltt+'</span>';
stockString +='</div>';
$('.stockTick').prepend(stockString);
});
}
});
</script>
<div class="stockTick"></div>
Here when I hardcode the stock exchange details it work.. for example if i put INDEXBOM:SENSEX
instead of gstock[i] in the getJSON url it works. But i need to get the data of more than 1 stock exchange but i get an error that Uncaught SyntaxError: Unexpected string
in the getJson line. I am not getting what the error is. May be a small one which i didnt notice. Can anyone help me with this?