2011-12-04 45 views
2

我希望能够使用jQuery AJAX从数据库中刷新或获取更新的记录。 而不刷新页面。加载页面后发出的Ajax请求

这里有个窍门,因为有人会发表评论,我该如何调用Ajax请求。由于该评论可以随时发布。

现在我只是加载页面加载记录。我希望能够在页面已经加载并发布评论时加载记录。

我只想一个简单的解决方案,这个项目不是为了生产。它只是我正在研究的一个学校项目。

我每隔20秒就会想到一个Ajax请求,或者在用户发表评论时可能会调用更新函数。

+1

在此处看不到问题 – Anonymous

+0

@Dan我在询问有关更新注释而不刷新页面的方法,当新评论已保存到数据库中时。 – SupaOden

+0

@asdgfassagas然后将其添加到您的问题,并使其具体。 – mithunsatheesh

回答

0
var auto_refresh_comments = setInterval(
function() { 
$('#comments').load('reload_comments.php?meeting='+ meeting_id+'').fadeIn("slow"); 
}, 5000); // refresh every 5000 milliseconds 

每5秒钟后重新加载#comment元素。

1

这样做。

<script language="javascript"> 

//function that refresh the comment list 
function load_new_comments() { 
    //jquery ajax call to pull the new records and update the comment area 
} 

//function to add a comment into dataase 
function add_new_comment() { 
    //jquery ajax call to add the new records 
    load_new_comments(); 
} 

//callback function.refresh time set to 30 seconds. 
function callback() { 
    setTimeout("pollingFunction();",30000); 
} 

//refresh function 
function pollingFunction() { 
    load_new_comments(); 
    callback(); 
} 

$(document).ready(function() { 
    pollingFunction();//initiating the function for the 1st time. 
}); 

</script> 
0

它很容易,做发布使用JavaScript的意见,每个后的JavaScript请求服务器,请刷新页面请求,以获得新的评论和帖子,在你的标记相应地分配他们,那么你可以再次使用的setInterval在第二个基础上进行这项操作。

相关问题