我正在计时器中进行AJAX调用。 AJAX调用给了我一些我需要根据" new"进行计算的数据。和#34;老"数据。问题是数据被覆盖。
function go_timer() {
var x_total = $('.old_value').text();
$.ajax({
type: 'GET',
url: 'http://scrape4me.com/yahoo?url=http://finance.yahoo.com/webservice/v1/symbols/asml.as/quote%3Fformat%3Dxml%26view%3D%E2%80%8C%E2%80%8Bdetail',
dataType: 'xml',
success: xmlParser
});
function xmlParser(xml) {
$('table tr.rows').remove();
$(xml).find('resource').each(function () {
$('table').append('<tr class="rows"><td class="movers"></td></tr>');
});
//end function
}
$('.old_value').text($('table tr td').text());
setTimeout(go_timer, 5000);
}
go_timer();
我想x_total
(旧)+ x_total
(新),然后坚持这个数字的结果。
答案 0 :(得分:1)
var x_total = 0;
function go_timer() {
$.ajax({
type: 'GET',
url: 'http://scrape4me.com/yahoo?url=http://finance.yahoo.com/webservice/v1/symbols/asml.as/quote%3Fformat%3Dxml%26view%3D%E2%80%8C%E2%80%8Bdetail',
dataType: 'xml',
success: xmlParser
});
function xmlParser(xml) {
$('table tr.rows').remove();
$(xml).find('resource').each(function () {
$('table').append('<tr class="rows"><td class="movers"></td></tr>');
});
x_total = x_total + parseInt($('table tr td').text());
//end function
}
setTimeout(function(){ go_timer()}, 5000);
//here you can have add logic
}
go_timer();