我遇到了.html()函數和YQL拉取數據的問題。數據正在拉動(如果使用YQL控制檯可以看到數據),但它不顯示或顯示任何結果。使用jquery拉取和顯示YQL財務數據並用.html()顯示YQL()
下面的代碼:
HTML
<ul id="TECO-container">
<li class="high">High: </li>
<li class="low">Low: </li>
<li class="close">Closing: </li>
<li class="volume">Volume: </li>
</ul>
JS
// initialise plugins
jQuery(function() {
tecoGetQuote('TECO');
});
//The above function is on a different .js than the below script.
var tecoGetQuote = function (symbol) {
var yqlURL = "http://query.yahooapis.com/v1/public/yql?q=";
var dataFormat = "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var realtimeQ = yqlURL + "select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + symbol + "%22)%0A%09%09&" + dataFormat;
$(function() {
$.getJSON(realtimeQ, function (json) { //YQL Request
//console.log(json.query.results.quote);
//<li class="high">High: -</li><li class="low">Low: -</li><li class="close">Closing: -</li><li class="volume">Volume: -</li>
$('#TECO-container .high').html('High: <span style="font-weight: bold; color:#FFBB00">' + json.query.results.quote.DaysHigh + '</span>');
$('#TECO-container .low').html('Low: <span style="font-weight: bold; color:#FFBB00">' + json.query.results.quote.DaysLow + '</span>');
$('#TECO-container .close').html('Closing: <span style="font-weight: bold; color:#FFBB00">' + json.query.results.quote.PreviousClose + '</span>');
$('#TECO-container .volume').html('Volume: <span style="font-weight: bold; color:#FFBB00">' + addCommas(json.query.results.quote.Volume) + '</span>');
});
});
};
這裏是的jsfiddle:http://jsfiddle.net/Darthfuzzy/cPFKE/4/
根據的jsfiddle的HTML/JS是完全有效的。所有跡象表明,它也應該運行。結果應該只顯示當前的市場數據,而且我之前看到過類似的功能。我只是不知道JS在哪裏運行。
該腳本應該非常簡單:股票行情是'TECO'(定義爲tecoGetQuote)。該函數然後從YQL JSON中提取財務數據,然後打印數據。然而,由於某種原因,無論我如何改變東西,它都不會顯示。
有人可以幫我指出問題在哪裏嗎?