【发布时间】:2015-08-01 07:45:16
【问题描述】:
如何让ajax连续调用一次5秒。
我用过setTimeout,如下所示,
setTimeout(function()
{
someFn();
}, 200);
但它使用更多的数据库连接。谁能告诉我一个连续调用函数 5 秒一次的有效方法。
我在 setTimeout 或 setInterval 中使用的函数将用于将值更新到数据库。因此这将增加数据库连接。并导致丢失数据库连接错误。所以我需要一些不会增加数据库连接的东西
我正在使用下面的代码
push_notification('<?php echo $user_details1[0]['id']; ?>');
setInterval(function()
{
push_notification('<?php echo $user_details1[0]['id']; ?>');
}, 10000);
function push_notification(driver_id)
{
var dataS = "&type=1&driver_id="+driver_id;
var SrcPath = "<?php echo URL_BASE; ?>";
var response;
$.ajax
({
type: "POST",
url: SrcPath+"driver/adminpushnotification/1",
data: dataS,
cache: false,
dataType: 'html',
success: function(response)
{
//some Functionality
}
});
}
【问题讨论】:
-
您的问题到底是什么?你想达到什么目标?您是否想每 200 毫秒发出一次 ajax 请求,但前提是之前没有待处理的请求?然后在 5 秒后停止发送?
标签: jquery ajax settimeout