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

Ajax problem, wont work in IE

P: n/a
The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);

setTimeout( 'get_last_updated()', 5000 );

} // end function

///////////////////////////////

function handleHttpResponse() {

if (http.readyState == 4) {

last_updated = http.responseText;

if ( ! first_updated ) { first_updated = last_updated; }

if ( last_updated - first_updated > 0 )
{ window.location = url; }
}
} // end function

///////////////////////////////////////////////////////

Feb 2 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
sq****@peoriadesignweb.com wrote:
The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);


As a guess, the problem is with wherever you've defined the http object.
It should look something like the stuff here:

<URL:http://jibbering.com/2002/4/httprequest.2004.html>
The relevant part is copied below where it the equivalent object is
called xmlhttp.
Creating the object

In Internet Explorer, you create the object using new
ActiveXObject("Msxml2.XMLHTTP") or new
ActiveXObject("Microsoft.XMLHTTP") depending on the version of MSXML
installed. In Mozilla and Safari (and likely in future UA's that
support it) you use new XMLHttpRequest()

This means that you need to show different script to different
browsers, as what works in one, will error in another. The script
below does this, and if it's not supported, the variable is set to
false to allow for appropriate error messages and recovery with
degrading to more normal HTTP transaction methods when the object
isn't available. This degradation is important, even in IE the objects
can often be blocked by slightly raised security settings (popular due
to the commonly exploited holes of course). Where possible degrade,
some approaches are talked about below, if you really can't, I'd
recommend providing an alternative page aswell. GMail for example has
said they'll be providing a less demanding version in the future,
hopefully with no javascript at all, full degradation.
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope
// with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}


--
Rob
Feb 2 '06 #2

P: n/a
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?

Feb 2 '06 #3

P: n/a
sq****@peoriadesignweb.com said the following on 2/2/2006 12:50 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
Thanks, I tried that code but still not working in IE.
Post a URL to a sample page that you have made that doesn't work in IE.

I think it may be because I am running an older version of IE6.0 ?
Doubtful but possible.
I will do a windows update to see if that fixes it?


You should update your windows and browser to make sure they are fully
patched but it shouldn't have anything to do with this.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Feb 2 '06 #4

P: n/a
sq****@peoriadesignweb.com wrote:
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?


You should already have a fully patched Windows system, but I doubt that
it will make any difference. XMLHttpRequest was introduced with IE 5.0.

IE 6.0 is the latest version, the full vision number I have is
6.0.2800.1106.xpsp2.050301-1526. IE 7 beta is around but kinda
irrelevant here.

Maybe it is security related... post a URL.
--
Rob
Feb 2 '06 #5

P: n/a

Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.


Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':

Feb 2 '06 #6

P: n/a
sq****@peoriadesignweb.com wrote:
Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.

Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':


It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.
--
Rob
Feb 2 '06 #7

P: n/a

RobG wrote:
It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.


At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.

I just did the windows update and it is still not working. Could it be
some other security setting inside IE 6, I am using: 6.0.2800.1106

Feb 2 '06 #8

P: n/a
sq****@peoriadesignweb.com wrote:
Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?

Stick in a few alerts to make sure your http object is valid.

--
Ian Collins.
Feb 2 '06 #9

P: n/a
sq****@peoriadesignweb.com wrote:
RobG wrote:
It doesn't work at all. You added the code to initialise the xmlhttp
object, but kept references to http in your original code. Change one
or the other.

At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.

I just did the windows update and it is still not working. Could it be
some other security setting inside IE 6, I am using: 6.0.2800.1106

I get an error from get_last_updated() just before http.send(). You have:

http.open( 'get', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);
Try:

http.open("GET", url);
http.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
handleHttpResponse();
}
}
xmlhttp.send(null);
--
Rob
Feb 2 '06 #10

P: n/a

sq****@peoriadesignweb.com wrote:
At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.


I would say the main reason why it's not working on Internet Explorer
is that you simply are not creating the xmlhttp object correctly for
IE. In your getHTTPObject function you are doing the following:

try
{
http = new XMLHttpRequest();
}
catch (e)
{
http = false;
}

You are using a method that would obviously would only work on non-IE
browsers. At least until IE7 shows up. Try using the following method
instead to create the XMLHttpRequest object:

if(window.XMLHttpRequest)
{
//for IE7, Mozilla, Safari, etc: use native object
var xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
//use ActiveX control for IE5.x and IE6
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

Feb 2 '06 #11

P: n/a
sq****@peoriadesignweb.com said the following on 2/2/2006 1:20 AM:
Randy Webb wrote:
Post a URL to a sample page that you have made that doesn't work in IE.


Here's a test page I have set up:

http://web.peoriadesignweb.com/dev/ajax/

http://web.peoriadesignweb.com/cgi-b...imple/demo.cgi

If you go to second page and make a reservation, then the first page
should update with a message saying 'Page has been updated':


The problem is not with the XMLHTTPRequest, it is a problem with your
cgi not returning what you think it is or what it should.

Find this section of your code:

if ( ! first_updated ) { first_updated = last_updated; }
if ( last_updated - first_updated > 0 )

Change it to look like this:
if ( ! first_updated ) { first_updated = last_updated; }
document.getElementById('myDiv').innerHTML +=
'First Updated = ' + first_updated +
' and last_updated = ' + last_updated + '<br>';
if ( last_updated - first_updated > 0 )

And then in your body add this HTML:

<div id="myDiv"></div>

Then test it. Then, go make a reservation, and watch your test page.
It doesn't return a modified value. I even added a new Date().getTime()
parameter to the URL to stop it from trying to get it from the cache and
it still doesn't update properly.

Have a look at your cgi script to make sure it is doing what it is
supposed to be doing.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '06 #12

P: n/a
web.dev said the following on 2/2/2006 2:10 AM:
sq****@peoriadesignweb.com wrote:
At the top of the script I have a line:

var http = getHTTPObject(); // We create the HTTP Object

so getHTTPObject basically returns the xmlhttp object created inside
it.


I would say the main reason why it's not working on Internet Explorer
is that you simply are not creating the xmlhttp object correctly for
IE.


It is properly being created. The problem is the return value from the
cgi script, not in the HTTPRequest Object.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '06 #13

P: n/a
Randy Webb wrote:
It is properly being created. The problem is the return value from the
cgi script, not in the HTTPRequest Object.


I have just added the code you suggested, however firefox is showing
the
correct result, but IE does not. Could it have to do with cacheing?

Feb 2 '06 #14

P: n/a
I have resolved the issue by changing it from GET to POST. Apparently
it was some caching problem in IE if I use GET.

Feb 2 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.