我在Javascript中有以下代码,有时它只是不起作用:
var new_c = 0;
function updateCounter()
{
var last_c = $("span#counter").text();
last_c = last_c.replace(",", "");
last_c = parseInt(last_c);
if (last_c < new_c)
{
last_c++;
$("span#counter").text(last_c);
}
}
function refreshCounter()
{
$("<div>").load("includes/ajax/meter/counter.php",
{
}, function() {
new_c = $(this).text().substr($(this).text().indexOf(";")+1);
new_c = new_c.trim();
new_c = parseInt(new_c);
});
}
window.setInterval("refreshCounter()", 1000);
window.setInterval("updateCounter()", 100);
如果我在执行加载调用后警告new_c
- 函数中的refreshCounter()
,它有时会返回一条空消息,有时它会返回页面counter.php
的内容,只是一个数字。