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

AJAX problem in IE (cache, maybe?)

P: 3
Hello everyone,

I have a little script that seems to hang up in internet explorer every now and again.

Basically, I have a php page that sets the following headers:

Expand|Select|Wrap|Line Numbers
  1.    header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
  2.    header( "Cache-Control: post-check=1,pre-check=2" );
  3.    header( "Cache-Control: no-cache, must-revalidate" );
  4.    header( "Pragma: no-cache" );
  5.    function setExpires($expires) {  
  6.        header(  'Expires: '.gmdate('D, d M Y H:i:s', time()+$expires).'GMT');  
  7.    }  
  8.    setExpires(5);
  9.  
Additionally, in this same page, there is a call to a javascript function using onload in the body tag.

That function starts one xmlhttprequest (which should take about 20 seconds or so to do), and also starts a second xmlhttprequest which continuously updates users with the status of the first request....

It looks something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function startSearch(usersess)
  3. {
  4.     var url="/runsearch.php";
  5.     url=url+"?usersess="+usersess;
  6.     url=url+"&sid="+Math.random();
  7.  
  8.     searchRequest=GetXmlHttpObject();
  9.     searchRequest.onreadystatechange=function(){
  10.          searchReqChanged();
  11.     }
  12.     searchRequest.open("GET",url,true);
  13.     searchRequest.send(null);
  14.     getSorter(usersess);
  15. }
  16.  
  17. function searchReqChanged(){
  18.    if (searchRequest.readyState==4)
  19.    {     
  20.     repeatSort = 0;
  21.    }
  22. }
  23.  
  24. function getSorter(usersess)
  25. {
  26.     var usess= escape(encodeURI(usersess));
  27.     var url="update.php";
  28.     url=url+"?sid="+Math.random();
  29.     url=url+"&usess="+usess;
  30.     sorterRequest=GetXmlHttpObject();
  31.                 sorterRequest.onreadystatechange=function(){
  32.            sorterReqChanged(usess);
  33.     }
  34.     sorterRequest.open("GET",url,true);
  35.     sorterRequest.send(null);
  36. }
  37.  
  38. function sorterReqChanged(usess){
  39.    if (sorterRequest.readyState==4)
  40.    { 
  41.     document.getElementById("results").innerHTML=sorterRequest.responseText;
  42.  
  43.     if (repeatSort != -1){getSorter(usess);}
  44.                 if (repeatSort == 0){repeatSort = -1;}
  45.    }
  46. }
  47.  
The problem is, in internet explorer, whenever I navigate to the page that starts up this function, sometimes it takes FOREVER to load. It is really strange, because when I take the no-cache headers off of the page, there is no problem. Regardless of the presence of the no-cache headers, it works fine in Mozilla.

I think it has to do with the AJAX because I've tried changing startSearc() to something like a simple alert and there are no troubles..

Any help would be much appreciated, as I've been stuck on this for quite awhile now...

Many thanks.
Jan 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: 3
Any ideas? I'm really having trouble with this one....
Jan 11 '08 #2

acoder
Expert Mod 15k+
P: 16,027
I'm not sure what might be causing the problem, but you could try making a unique request instead of setting cache headers. Use the Date object and append it to the url:
Expand|Select|Wrap|Line Numbers
  1. url+new Date().getTime();
Hope that helps.
Jan 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.