By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,935 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,935 IT Pros & Developers. It's quick & easy.

Ajax issue with Internet Explorer (no error message either)

P: 65
I have created a little chat application that seems to work 100% on Mozilla Firefox, Google Chrome, and Safari, (tried it in Opera, and it seems to work, but the cookies are screwing everything up; this is probably because my install is not being run under an administrator account), but not Internet Explorer.

Chat • Login
http://preview.moltx.name/chat_v2/library.js

Everything works fine, up until you get to the chat room itself. Internet Explorer just sits, and does nothing. Doesn't even have an error. It seems to be able to send data (but not fully; send a message using Internet Explorer, and then check the active users list on another browser), and is completely non responsive to data received.

It's made with JavaScript + PHP.
Nov 27 '08 #1
Share this Question
Share on Google+
15 Replies


P: 65
I have repaired one issue but it didn't solve the problem with Internet Explorer properly displaying what it receives.

Internet Explorer was sending two messages when submitted; one empty, one of the content you have submitted. I put a server-side filter to prevent empty messages from being submitted (since it also causes a bug with the other browsers) so now the messages submitted from Internet Explorer appear on the other browsers properly.

Does this have anything to do with Internet Explorer, not supporting the World Wide Web Consortium Document Object Model perhaps?
Nov 27 '08 #2

acoder
Expert Mod 15k+
P: 16,027
The most probable reason is that IE is caching the response, so no further requests to the same URL are made. To disable caching, add some headers, or make the URL unique, e.g. by adding the timestamp.
Nov 28 '08 #3

P: 65
I've added the following headers to my server's response for every page:
  • Content-Control: no-cache, must-revalidate
  • Expires: -1
  • Pragma: no-cache

Nothing appears to have changed, except on Firefox, which appears to no longer "not do anything" (once in a while, it wouldn't actually reload the page containing the script, causing the server to not reset the message counter, and thus not receive all messages).

I cleared my history/cache/cookies on Internet Explorer on both of my computers several times. With no change in behavior of the script.

Even if it was caching the response, it should at least receive one message, "Connected.," no matter what from my server and after receiving it, it should automatically strip the <p>Connecting...</p> from the chat log, and from the users list, and replace the one in the chat history with, "Connected.," and the one in the users list with the username (colored green) that you signed in with.

Please note that if you're testing this out, you're not really "registering" on the site, just use any old username to "log in" (it doesn't really require you to be registered in any way, hence no password box) and it will add it to the database temporarily to track which room you're in and whatnot, to send the messages you have not received yet when the script queries for them.

I also tried the timestamp thing by adding +"&timestamp="+unixTime () to the XMLHttpRequest.open url, and same thing; no change in script behavior.
Nov 28 '08 #4

acoder
Expert Mod 15k+
P: 16,027
I notice that you have this in your code:
Expand|Select|Wrap|Line Numbers
  1. if (window.IExplore)
  2.                             {
  3.                                 document.write (this.responseText);
  4.                             }
I'm not sure what it's for, but using document.write() after the page has loaded has unexpected results. It reopens the page for writing. If you want to add content to the page after loading, use appendChild().
Nov 29 '08 #5

P: 65
That is not there for "functional" reasons. I use document.write when I can't seem to figure out what is going wrong to just "dump" variables to the page, and which on IE, it's not receiving any data for it to dump, so if that actually worked... I'd remove it, knowing that the variable there isn't the cause of IE not working.

So right now that's definitely not causing any problems. It will need to be removed in the future when I do figure out what's wrong with IE, but right now it's there so that once I do fix the problem with data not coming in it'll be like "DING <?xml version="1.0" encoding="UTF-8" ?><messages><type>history</type><number>1</number><message><content>Conntected.</content></message></messages>" right in the middle of the screen. A hallelujah moment!
Nov 30 '08 #6

P: 65
Alright, it looks like it is an issue with appendChild in Internet Explorer. It is supported, but in a different way. I spent about an hour searching Google for what was going wrong, but now need to find a solution.
Nov 30 '08 #7

P: 65
Never mind, I have no clue any more. I dumped a document.write and wrote all the text to the screen on all browsers but Internet Explorer, which points the blame finger back to XMLHttpRequest.
Nov 30 '08 #8

P: 65
It appears as if "this." anything is underfined in Internet Explorer. Is there any way to have this. populated properly?
Nov 30 '08 #9

acoder
Expert Mod 15k+
P: 16,027
See this. You might try explicitly adding it. Using an object for the Ajax calls should also solve this problem.
Nov 30 '08 #10

P: 65
According to that guide (which seems to explain everything in the exact way I was pretty sure it was handled) it is working as expected in Firefox, Opera, Google Chrome, and Safari, but not in Internet Explorer. It only mentions one thing about Internet Explorer with a specific function; attachEvent sends it as a reference, causing this to be a reference to window rather than the element that it is a child of.
Nov 30 '08 #11

P: 65
Well, I fixed the XMLHttpRequest issue; this is not inherited properly on Internet Explorer it seems, period. So I'm never mucking around with that until the 8th version of Internet Explorer comes out; we'll see what it can do right for once.

Anyways with that out of the way the W3C DOM method is causing problems in Internet Explorer (I'm actually getting errors, thankfully). However, I don't know why, especially with the check in place.

It's giving me an error on line 140; the script automatically checks if it is set or not; if it is, then it goes to line 140, and grabs the data. But Internet Explorer is claiming it's set when it's not.
Nov 30 '08 #12

P: 65
Okay, I guess I repaired that issue; used element.length > (0) rather than typeof (element [0]) !== 'undefined'.

Now it's giving me a Type Mismatch on the removeChild statement I've got on line 222 or 223.
Nov 30 '08 #13

P: 65
Text is being displayed! Major progress!
Nov 30 '08 #14

P: 65
Fully functioning now. :)

Thank you for your help guys.
Nov 30 '08 #15

acoder
Expert Mod 15k+
P: 16,027
Great work. I learnt one or two things from this thread because I don't usually code XMLHttp in the way that you did. Thanks for all the progress reports. It helps when users post at each step. Finally, I'm pleased for you that you got it working :)
Dec 1 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.