【发布时间】:2012-05-01 23:45:12
【问题描述】:
我在 jStockticker 的 html 页面中有以下内容。
<div id="ticker" class="stockTicker" style="width: 100%">
<span class="quote">Stock Quotes: </span>
<span id="tickerValues-AAPL">
<span class="up">
<span class="quote">AAPL</span>
462.12
</span>
<span class="down">
<span class="quote">AAPL</span>
232.32
</span>
<span class="eq">
<span class="quote">AAPL</span>
451.52
</span>
</span>
<span id="tickerValues-GOOG">
<span class="up">
<span class="quote">GOOG</span>
623.12
</span>
<span class="down">
<span class="quote">GOOG</span>
502.32
</span>
<span class="eq">
<span class="quote">GOOG</span>
545.52
</span>
</span>
</div>
并使用 jQuery im 使用 ajax 更新实时值
$(document).ready(function() {
$("#ticker").jStockTicker({interval: 45});
var i = setInterval(function ()
{
$.ajax({
type : "POST",
url : 'http://localhost:8080/Data.xhtml',
dataType : "json",
success: function(data) {
$.each(data, function(i, item) {
if(data[i].LastT == "+"){
$("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"up\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
}else if(data[i].LastT == "-"){
$("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"down\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
}else if(data[i].LastT == " "){
$("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"eq\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
}
});
$("#ticker").jStockTicker({interval: 45});
},
error : function() {
alert("");
}
});
return false;
}, 6000);
});
问题是当发生更新时,代码滚动会回到开头并开始滚动,而不是在连续滚动时获取更新的值。
【问题讨论】:
-
我可能错了,但是,您不应该对某些 servlet(或硬编码的 xml/json)执行 ajax GET 吗?而不是 GET 到 xhtml?
-
你可以同时做这两种方式,所以它不会影响这个
标签: json jsf jquery jquery-plugins