July 14th, 2013, 03:08 AM
-
How do I call jQuery function every 3 seconds?
Suppose I have an html code :
html Code:
<html>
<head>
<script src="includejquery.js"/>
<script type="text/javascript" src="chat.js"></script>
<title>Chat</title>
</head>
<body onload="process()">
<div id="chatmessages">
</div>
</body>
</html>
Suppose I have a jQuery code(chat.js) :
javascript Code:
function process(){
$.get('chat.php', function(data) {
$("#chatmessages").html(data+"<hr />");
});
});
As you see its a very simple and basic code to implement chatting.
And I intend to call the function process() every 3 seconds.
What do I do to call the function process() every 3 seconds?
July 14th, 2013, 03:45 AM
-
July 14th, 2013, 12:48 PM
-
Originally Posted by Jacques1
Sorry for troubling and not trying before posting.
I found out the solution.
Thanks anyways. Will remember what you said from next time.
My solution :
javascript Code:
function process(){
$.get('chat.php', function(data) {
$("#chatmessages").html(data);
});
setTimeout(function(){
process();},3000);
}