Page 1 of 1

Ajax calls

Posted: Thu Jun 10, 2010 10:30 pm
by echofool
Hey,

I been working on an ajax chat script which communicates with my database to get the chat logs, but i've got a few questions and hopeing i can get some guidance.

Firstly my script:

Code: Select all

function sendMessage()
{
     $.ajax({
          type: "POST",
          url: "chatpost.php", // php script to insert new message into message table
          async: false,
          data: "message="+$("#myMessage").val(),
		  
      });
		$("#myMessage").val("");
	   return false;
}



function updateShouts(){
    $('#chatArea').load('chat.php'); // execute chat.php
}
setInterval( "updateShouts()", 500 ); //call function every half a second
Now what im trying to do is make it so that it only fetches the chat when the chat logs have updated. Currently it fetches every half a second regardless of new updates which is not good in reality.

My chat table in database is |RecordID | Message | UserID |

Hope you can help me out :)

Thanks

Re: Ajax calls

Posted: Mon Jun 14, 2010 5:21 am
by Phoenixheart
(Coming from top of my head) You may want to add some caching / modified headers stuffs to your server code.
Another approach is pushing (aka Comet / Reversed Ajax) but this is much more advanced.