AJAX works in IE6 but not IE7 or Firefox

S

Steve Wright

I have an AJAX routine on a webpage that is working in IE6, but not IE7
or Firefox v2.0.0.2

The webpage is

http://www.a-drop-in-the-ocean.co.uk/CWS/monitor10bins.php?quarry=401

The AJAX routine is encapsulated in the module

http://www.a-drop-in-the-ocean.co.uk/CWS/js/timer.js

What it is supposed to do is every ten seconds, read the contents of the
file http://www.a-drop-in-the-ocean.co.uk/CWS/401/seqno.txt. This file
just contains the number 46955. If this number changes then the page
will refresh.

The timer routine, counts down the 10 seconds, displaying the counter in
the top right hand corner. Once the counter hits zero, it triggers the
AJAX request.

The onload event also triggers the AJAX request to get the initial value
of the number.

I presume that IE7 and FF use the XMLHttpRequest() function and that I
must have coded this incorrectly. But what is wrong with it?

Interestingly, the firebug extension in FF, shows the request and
response headers along with the response 46955.

Fixing this is not critical at the moment as IE6 is our company
standard. But at some stage we will migrate to IE7...

Has anybody got any ideas?
 
J

Jeremy

Steve said:
I have an AJAX routine on a webpage that is working in IE6, but not IE7
or Firefox v2.0.0.2

The webpage is

http://www.a-drop-in-the-ocean.co.uk/CWS/monitor10bins.php?quarry=401

The AJAX routine is encapsulated in the module

http://www.a-drop-in-the-ocean.co.uk/CWS/js/timer.js

What it is supposed to do is every ten seconds, read the contents of the
file http://www.a-drop-in-the-ocean.co.uk/CWS/401/seqno.txt. This file
just contains the number 46955. If this number changes then the page
will refresh.

The timer routine, counts down the 10 seconds, displaying the counter in
the top right hand corner. Once the counter hits zero, it triggers the
AJAX request.

The onload event also triggers the AJAX request to get the initial value
of the number.

I presume that IE7 and FF use the XMLHttpRequest() function and that I
must have coded this incorrectly. But what is wrong with it?

Interestingly, the firebug extension in FF, shows the request and
response headers along with the response 46955.

Fixing this is not critical at the moment as IE6 is our company
standard. But at some stage we will migrate to IE7...

Has anybody got any ideas?

What is not working about it? The AJAX code looks like it should work
in both firefox and IE, so I don't think that's your problem.

I would guess off the top of my head that the response is getting cached
(despite sending if-modified-since) and so you're not getting back an
updated response. There are a lot of ways to prevent this, such as
using a POST request instead of GET and/or appending a randomized query
string.

Jeremy
 
E

Erwin Moller

Steve said:
I have an AJAX routine on a webpage that is working in IE6, but not IE7
or Firefox v2.0.0.2

The webpage is

http://www.a-drop-in-the-ocean.co.uk/CWS/monitor10bins.php?quarry=401

The AJAX routine is encapsulated in the module

http://www.a-drop-in-the-ocean.co.uk/CWS/js/timer.js

What it is supposed to do is every ten seconds, read the contents of the
file http://www.a-drop-in-the-ocean.co.uk/CWS/401/seqno.txt. This file
just contains the number 46955. If this number changes then the page
will refresh.

The timer routine, counts down the 10 seconds, displaying the counter in
the top right hand corner. Once the counter hits zero, it triggers the
AJAX request.

The onload event also triggers the AJAX request to get the initial value
of the number.

I presume that IE7 and FF use the XMLHttpRequest() function and that I
must have coded this incorrectly. But what is wrong with it?

Interestingly, the firebug extension in FF, shows the request and
response headers along with the response 46955.

Fixing this is not critical at the moment as IE6 is our company
standard. But at some stage we will migrate to IE7...

Has anybody got any ideas?

Hi,

go to: www.w3schools.com

Follow the AJAX link.
Read through it. It won't take more than 15 minutes if you are familiar with
JS.
You will find a nice routine at the end that gives you your xmlhttprequest
on all platforms that support it.

Regards,
Erwin Moller

PS: Shame your company isn't migrating to FF.
 
S

Steve Wright

Your request.open call only has 2 parameters,

request.open ('get', url);

the docs for XMLHttpRequest for Mozilla/Firefox say it needs 3 -- and
last time I checked, Firefox does indeed need the 3rd parameter.

req.open('GET', 'http://www.mozilla.org/', false);

<http://developer.mozilla.org/en/docs/XMLHttpRequest>

Whilst you are correct, that is not the root cause of the problem.

I have changed the request.open to pass true as the 3rd parameter, but
this has no effect in Firefox.

(Please note I am trying this at work, so I haven't changed the
version I posted to the group yet - I'll do that tonight).

My next idea is to rewrite using the prototype library routines (if I
can get my head around them)
 
B

Bart Lateur

Steve said:
Whilst you are correct, that is not the root cause of the problem.

I have changed the request.open to pass true as the 3rd parameter, but
this has no effect in Firefox.

While that may be true, in my haste, I got the value of the parameter
wrong. It is false for synchronous, and true for asynchronous mode. As a
note on the page says:

Note: This example works synchronously, so it will block the
user interface if you call this from your JavaScript. You should
not use this in practice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top