PDA

View Full Version : Ajax Chat


Endeavor88
09-24-2005, 02:12 PM
I have recently been working on an Ajax chat program. The way it works is that I send data in XML format for sending messages, and I retreive XML data for retrieving messages. Anyways I sent an interval to retreive messages every 5 seconds(default; or the user can set it). I tested it in firefox and it works perfectly. But in IE, it loads all the messages once, and then never updates. You can still send messages in IE, but the user will never know it.
Here's the site:
http://endeavor.aspfreeserver.com/ubiquitous/chat.php

Someone please tell me why the script does not work in Internet Explorer. :thumbup:

Endeavor88
09-25-2005, 01:56 AM
I think the reason is that Internet Explorer cached the xmlhttprequest results. If you saw my other page, http://endeavor.aspfreeserver.com/ubiquitous/ , then you can see what I mean. You can double click on any word to receive its definition. In Internet Explorer, if you double click on the same word twice, IE will not request the same definition again. Instead, it will load what it previously download via the xmlhttprequest. However, firefox reloads the definition on each double click. It appears that IE caches the xmlhttprequest results and saves it for the session, but firefox does not save it.

Is there a way to put a expiration date on the xml data or the xmlhttprequest so that Internet Explorer will download new data for each request?

Endeavor88
09-25-2005, 07:07 PM
:ak47: :thumbup:
I was correct. I need to add a header for "Cache-control: no-cache" in php.

Jon Hanlon
09-26-2005, 09:32 PM
It's best not to rely on cache control -- none of it works 100%.
Internet Explorer will cache the responses if the parameters are the same.
eg. &from=sinbad&body=sailing

What I do is add a unique id which is never accessed but constantly changing:
+ "&uid=" + (new Date()).getTime()

This will force a unique response for each browser.

Endeavor88
09-26-2005, 10:03 PM
Thanks, I'll try that.

Endeavor88
09-26-2005, 10:12 PM
It seems to work both ways:
I can add some php code:
header("Cache-Control: no-cache");
or I can add an extra parameter that is constantly changing,
"&uid=" + (new Date()).getTime()

The 2nd method works with POSTing and GETing. I can use the time when posting messages so that I know when the message was posted. However, I don't see a way to use it when receiving new messages from the server.

How hazardous is using cache control? Take also into account that some browsers might not even support the xmlhttprequest, and therefore cache control would not matter anymore with those browsers.

Jon Hanlon
09-27-2005, 06:37 PM
Here's Microsoft on the subject:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q234067