bPHP Posted March 4, 2010 Share Posted March 4, 2010 Hi! I'm pretty new to Ajax, and I'm creating a web chat. I have a <div> inside my main chat.php that is being refreshed every time. It is something like this: <div class="box" id="chatWindow"> <div id = "moniter"> </div> </div> The moniter function is refreshing, by using something like this inside a JS file: function moniter() { xmlHttp_moniter = GetXmlHttpObject_parcel() if(xmlHttp_moniter == null) { alert("browser does not support HTTP Request") return } var url="moniter.php?random=" + 23 //This is set to date time actually, but I was doing some changes. xmlHttp_moniter.onreadystatechange = stateChanged xmlHttp_moniter.open("GET",url,true) xmlHttp_moniter.send(null) } The php then loads all the divs, it first goes to the db, reads all messages and displays them accordingly inside the chat box (adding divs with the nicknames of the people). My main problem is that this is constantly refreshing, so it is impossible to copy text from the chatbox (for example if the user wants to show his/her conversation to someone else, can't do any copying because the refresh does not allow him/her to do it). How can I solve this? Thanks very much! Quote Link to comment Share on other sites More sharing options...
bPHP Posted March 6, 2010 Author Share Posted March 6, 2010 How can i do a div ajax refresh based not on timing but on a condition? For example if an sql table was updated? I don't really know how to do this, if someone can give me some insight on how to properly design this... I have a php that calls a JS function using Ajax and loads from another php after x seconds... I would like this to be based on a condition but I'm really lost... Any help or suggestions will be appreciated! Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 You can't check a condition on the server and then update on the client. The only way is to have the client periodically check with the server if the condition has been met (which is what you are doing). Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted March 7, 2010 Share Posted March 7, 2010 You could use a 'copy all' link which stores the current content in the user's clipboard instead of forcing them to highlight. Quote Link to comment Share on other sites More sharing options...
bPHP Posted March 8, 2010 Author Share Posted March 8, 2010 But then how will I know if I need to get back to the db for updated data? Other users can also update the db. :S Quote Link to comment Share on other sites More sharing options...
bPHP Posted March 8, 2010 Author Share Posted March 8, 2010 But then how are chats done? Is there a constant checking for new messages? I believe there should be some way of not checking all the time the db, I see it as a lot of overhead to be constantly doing selects :s Unless I'm wrong and that's the way it has to be done... Quote Link to comment Share on other sites More sharing options...
trq Posted March 8, 2010 Share Posted March 8, 2010 There is no connection using http. Even if you write a server side script to check your db periodically, it would have no way of knowing where to send any updates. It must be requested via the client. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.