简体   繁体   English

这个 jquery 刷新脚本安全吗?

[英]Is this jquery refresh script safe?

I use this script to update a div , gathering new information constantly.我使用这个脚本来更新div ,不断收集新信息。 It works well in every browser, except in Google Chrome where it hangs after a while and the browser turns blue and a small sad graphic tells me there's something wrong.它在所有浏览器中都运行良好,除了在谷歌浏览器中它会在一段时间后挂起并且浏览器变成蓝色并且一个悲伤的小图形告诉我有问题。 The rest of the browser stays intact, it's only the affected tab so it has to do something with this code:浏览器的 rest 保持不变,它只是受影响的选项卡,因此它必须使用以下代码做一些事情:

<script type="text/javascript">
    setInterval("SANAjax();", 500); 
    $(function(){
        SANAjax = function(){
            $("#target").load("page.php");
        }
    });
</script>

Is it not safe to refresh a div that many times?多次刷新一个div不安全吗? Will it overload or what not?它会超载还是不会?

I would do it a bit different than that.我会做的有点不同。

Untested:未经测试:

$(function(){
    SANAjax();
});

function SANAjax(){
    $('#target').load('page.php', function(){
        setTimeout(SANAjax, 500);
    });
}

This makes sure a new request is being made after the current one is finished.这可确保在当前请求完成后发出新请求。 http://api.jquery.com/load/ http://api.jquery.com/load/

The simple way简单的方法

$(function(){
        setInterval(function(){
            $('#target').load('page.php');
        }, 500)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM