View Full Version : function doesnt get called in ie

03-29-2009, 04:49 PM
i am using this function to permanently call from a database a string wich represent a background color value so i can get a permanent redraw but the function doesnt get called in ie. any thoughts appreciated

var p=new xhr()
function getajax(){
if (p.readyState == 4) {
var div=document.getElementById("thediv").style.backgroundColor=p.responseText;


03-29-2009, 05:21 PM
This does work in Mozilla/Firefox, Safari or Opera?

Can we see the 'xhr' class? Does it test for browser type and return the correct XMLHttpRequest or ActiveXObject?

Try changing the method order to open, onreadystatechange, send.

BTW, the setTimeout call should simply reference the function name, e.g. 'getAjax', not 'getAjax()'.

03-29-2009, 05:25 PM
the xhr class is simple and does reference the ie methods:

function xhr(){
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch (e){
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;

i try setTimeout('getajax',100), but still nothing on ie,
yep it works on safari and ff

03-29-2009, 05:35 PM
A couple more thoughts..

What version of IE?

I'm wondering if it has to do with your selector:

var div=document.getElementById("thediv").style.backgroundColor=p.responseText;

Throw a couple of alert()'s in there and verify that IE actually is using an XHR call and returning text to the page. If so, it might simply be your CSS selector.

Also, I note that your syntax is missing some semicolons, IE's scripting engine can be a buggaboo about things like that.

03-29-2009, 05:58 PM
ok thanks, i'll keep on debugging :mad:

03-30-2009, 12:37 AM
I finally find out , ie was caching the timeout i added this:

p.setRequestHeader('If-Modified-Since','Wed, 05 Apr 2006 00:00:00 GMT');
and the setTimeout function worked.

03-30-2009, 01:09 AM
Ah, the old IE caching problem. I know it well (http://www.codingforums.com/showthread.php?t=142180). ;)