Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE not updating with my ajax polling implementation

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hello,

I am new to the ajax methodology so please bear with me.

I have implemented a javascript poll, every second, to my java servlet for message board data. Upon return, I display this data in some div on the jsp page. I noticed in Firefox this works, but in IE, unless I change my "check for new versions of stored pages" to "every time i visit" under tools/internet options/settings, the page divs do not update.

Obviosuly I must be doing something wrong, because the client shouldnt have to adjust browser settings. Any advice would be appreciated.

below is my code...

Code:
function pollServlet(){
	//alert("in")
	var xmlHttp;
  	try{ // Firefox, Opera 8.0+, Safari    
  		xmlHttp=new XMLHttpRequest();
  	}catch (e){ // Internet Explorer
  		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}catch(e){
  			try{
  				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  			}catch(e){
  				alert("Your browser does not support AJAX!");
  				return false;
  			}
  		}
  	}
    xmlHttp.onreadystatechange=function(){
    	if(xmlHttp.readyState==4){
        	//document.add.message.value=document.add.message.value+" "+xmlHttp.responseText;
        	//document.getElementById.crap.value=xmlHttp.responseText;
        	document.getElementById("contentarea").innerHTML=xmlHttp.responseText
        	//alert(xmlHttp.responseText)
        }
    }

    
    xmlHttp.open("GET","blogEntry",true);
    xmlHttp.send(null);  
    
    init();
}

function init(){
setTimeout("pollServlet()",3000);
}

<body onload=init()>

 
Like I posted on the other question, your data is being cached and so by default, IE will use the cached version of the AJAX request.

You fix this by having something that is always containing a different value respond with the server.

I really don't know how to do this in your case, but in the case of calling another URL, you pass a timestamp.

I'm by no way an AJAX guru, but I do know that caching is your problem, sorry I can't help with passing a changing variable, but the first place I'd start is with blogEntry.

<.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top