Javascript .load调用在setInterval()内只工作一次
我不能让间隔刷新一次以上Javascript .load调用在setInterval()内只工作一次,javascript,c#,jquery,ajax,Javascript,C#,Jquery,Ajax,我不能让间隔刷新一次以上 window.setInterval(function() { $('#testButton').load('test', function (response, status, xhr) { if (status == "error") { document.write("helloworld"); } else { $('
window.setInterval(function() {
$('#testButton').load('test', function (response, status, xhr) {
if (status == "error") {
document.write("helloworld");
}
else {
$('#testButton').replaceWith(response);
}
});
}, 5000);
我在.load
中调用的测试函数如下(我只是获取当前时间):
问题在于:
$('#testButton').replaceWith(response);
在成功返回值时,替换元素,使其不再存在于函数的未来执行中(函数实际执行,但生成错误)。替换为:
$('#testButton').html(response);
更改其内容,而不仅仅是用ajax的返回值替换元素本身
$('#testButton').html(response);