【发布时间】:2013-09-26 17:58:39
【问题描述】:
我想调用 Ajax 从数据库中获取所有 cmets。
现在如何检查要运行的 Ajax 脚本,当只有某人 cmets 时。
与 stackoverflow 通知 相同。当我们评论问题时,通知会出现而不重新加载页面(即在运行时)。
现在我每 10 秒一次又一次地运行相同的 Ajax 脚本,当我认为这是一种不好的方式时。所以这是我的工作 Ajax 代码:
$(document).ready(function(){
setInterval(function(){
$.ajax({
type: "GET",
url: "ajax_files/reload_notifications.php"
}).done(function(result) {
var $notifications = $('#notification_area');
if ($notifications.length > 0) {
$notifications.html(result);
}
});
}, 10000);
});
【问题讨论】:
-
使用 HTML5 服务器发送事件,更好
-
@JasonOOO 你能给我举个例子吗?或者帮助我的代码使用它。我会很感激的。
-
使用 .append() 代替 .html()。
-
@GurminderSingh 不,亲爱的,这不是问题所在。我想知道评论什么时候出现在数据库上,所以同时只有我的脚本应该运行
标签: javascript php jquery mysql ajax