多次调用 ajax 函数后,我注意到大量进程被攻击,并且我的网站被阻止(但它在本地主机上运行良好)。
jquery调用和进程之间有什么关系? 是主机的安全性阻止了它吗?
我有很多函数可以进行自动刷新。如何刷新而不阻止我的网站?
<小时/>var auto_refresh3 = setInterval( function () {
//tchata2.php is a file checking the new messages
$.post("tchata2.php",{FID:identif},function (data){
if($('#newmsg').val()!=data){
$('#newmsg').empty();
$("#newmsg").append(data);
}
});
}, 1000); // checking for other messages after 1 second
最佳答案
在 ajax 完成延迟后再次调用该函数将是一个更好的主意并增加时间延迟。在外部使用 setInterval
将发送多个连续的请求,这可能会因内存使用过多而破坏浏览器。
var auto_refresh3 = function () {
$.post("tchata2.php",{FID:identif},function (data){
if($('#newmsg').val()!= data){
$('#newmsg').empty();
$("#newmsg").append(data);
}
setTimeout(auto_refresh3, 5000);
}).fail( function(xhr, textStatus, errorThrown) {
setTimeout(auto_refresh3, 5000);
});
}
关于javascript - jquery 调用导致服务器出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35319558/