Jump to content

Refresh problems


bPHP

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.