Closed Thread
Results 1 to 3 of 3

Thread: help: how to calling ajax every 3 second

  1. #1
    saint_xaver's Avatar
    saint_xaver is offline Newbie
    Join Date
    Aug 2008
    Location
    Indonesia
    Posts
    15
    Rep Power
    0

    help: how to calling ajax every 3 second

    hi everyone, I need help, I make a chat room n make function to call ajax every three second to refresh list of the chat, but don't work just once it work and didn't called every 3 second. here is my code:
    Code:
    <body onload="loadChat(<? echo $_GET['idroom']; ?>)">
    
    function loadChat(id)
    {
    	getChat(id);
    	setInterval("getChat("+id+")",5000);
    }
    
    
    function getChat(idroom)
    {
    	
    	if(XMLHttpRequestObject) 
    	{		
    		
    		var obj2 = document.getElementById("FCKeditor1");
    		XMLHttpRequestObject.open("POST", "isi.php");
    XMLHttpRequestObject.setRequestHeader('Content-Type','application
    /x-www-form-urlencoded');
    XMLHttpRequestObject.onreadystatechange = function()
    			{
    	if (XMLHttpRequestObject.readyState == 4 
    &&	XMLHttpRequestObject.status == 200) 
    			{
    		if (XMLHttpRequestObject.responseText)
    				{
    						
    		obj2.value = XMLHttpRequestObject.responseText;
    						
    					else
    				alert ("error");
    				}
    			}
    		
    	XMLHttpRequestObject.send(null);
    	}
    }
    thx for the help.
    regards

    eko.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: help: how to calling ajax every 3 second

    this:
    Code:
    setInterval("getChat("+id+")",5000);
    should be placed in the onload event because it starts the function every 5 seconds
    if you dont wanna replace the onload function use setTimeout() instead of setInterval() . ame syntax but setInterval runs the function every N seconds, and setTimeout runs the function after N seconds
    yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  4. #3
    saint_xaver's Avatar
    saint_xaver is offline Newbie
    Join Date
    Aug 2008
    Location
    Indonesia
    Posts
    15
    Rep Power
    0

    Re: help: how to calling ajax every 3 second

    thx for your reply, but I just realize my mistake, not the function setTimeout just a little mistake. thx for the help.
    regards eko

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. calling a C DLL from C#
    By yan302 in forum C# Programming
    Replies: 2
    Last Post: 07-19-2010, 07:14 AM
  2. Replies: 10
    Last Post: 04-16-2010, 04:58 AM
  3. calling another page?
    By hayschooler in forum PHP Development
    Replies: 2
    Last Post: 03-22-2010, 06:10 AM
  4. calling .NET from C?
    By sardaukar in forum C# Programming
    Replies: 0
    Last Post: 07-17-2008, 02:33 AM
  5. Calling another functioin?
    By MinoriZ in forum C and C++
    Replies: 11
    Last Post: 08-30-2007, 11:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts