Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .load调用在setInterval()内只工作一次_Javascript_C#_Jquery_Ajax - Fatal编程技术网

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