gpt4 book ai didi

javascript - 在定时器内进行 AJAX 调用并保持值

转载 作者:行者123 更新时间:2023-11-30 00:22:15 24 4
gpt4 key购买 nike

我在定时器内进行 AJAX 调用。 AJAX 调用为我提供了某些数据,我需要根据"new"和“旧”数据进行计算。问题是数据被覆盖了。

    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(新),然后保留该数字的结果。

最佳答案

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();

关于javascript - 在定时器内进行 AJAX 调用并保持值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32718314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com