...

View Full Version : function doesnt get called in ie



sybil6
03-29-2009, 03: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(){
p.open('get',"pid_01_ajax_query.php?",true)
p.send(null)
p.onreadystatechange=function(){
if (p.readyState == 4) {
var div=document.getElementById("thediv").style.backgroundColor=p.responseText;
//alert("o")
setTimeout('getajax()',100)
}
}
}

getajax()

bdl
03-29-2009, 04: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()'.

sybil6
03-29-2009, 04: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

bdl
03-29-2009, 04: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.

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

sybil6
03-29-2009, 11:37 PM
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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum