Ajax calls

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Ajax calls

Post 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
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Re: Ajax calls

Post 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.
Post Reply