#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2

    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?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    there's this thing called Google. Learn to use it.

    The very first result already contains the solution: window.setInterval()
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2
    Originally Posted by Jacques1
    Hi,

    there's this thing called Google. Learn to use it.

    The very first result already contains the solution: window.setInterval()
    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);
    }

IMN logo majestic logo threadwatch logo seochat tools logo