I'm trying to make a wall post like Facebook. I need to refresh the content div after every ten seconds and the div shouldn't refresh while the user is typing a comment. The content is reloading but is not stopping. Actually, I want to stop it when i click id = 'comments_option'
.
I tried this and called the function reload(uid) at $(document).ready
var intervalId = null;
function reload(uid) {
intervalId = setInterval(function () {
var ol = $('#home_list');
var start = ol.children().length;
$.post('ajax/reloadhome.php', {
uid: uid,
start: start
}, function (data) {
$('#buzzfetch ul').html(data);
});
}, 5000);
$('#comments_option').click(function () {
clearInterval(intervalId);
});
}