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

AJAX Script not working in IE

P: 3
I am running a code that works just fine in Firefox, but seems to have trouble in IE. The basic idea is that a travel search process is initiated with one ajax call, and a 2nd ajax call 'updates' the page with the results that have been retrieved thus far. This 2nd call loops until the first call (the search) is complete.

Everything works fine in Firefox, but in IE, the 2nd call doesn't work until the very end when the 1st call is complete. In other words, in IE, you don't see the results being continuously updated -- you just see the final set of results at the end.

Now, the search (i.e. the first AJAX call) does use the cURL library with php, which may have something to do with it. I thought it may be the 'two simultaneous connection' thing, but why would it work in Firefox without any problem??

Here is JS I'm using...

Expand|Select|Wrap|Line Numbers
  1.  
  2. function startSearch(sess, inmonth, inday, inyear, outmonth, outday, outyear, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp, exp)
  3. {
  4.     var loadingtext    = '<img src=/images/loader.gif><br>Please wait while we process your search...<br>Searches may take up to a minute.'; 
  5.     document.getElementById("loading").innerHTML=loadingtext;
  6.     repeatSort = 1;
  7.  
  8.         var url="dosearch.php";
  9.         url=url+"?sess="+sess;
  10.         url=url+"&inmonth="+inmonth;
  11.         url=url+"&inday="+inday;
  12.         url=url+"&inyear="+inyear;
  13.         url=url+"&outmonth="+outmonth;
  14.         url=url+"&outday="+outday;
  15.         url=url+"&outyear="+outyear;
  16.         url=url+"&sid="+Math.random();
  17.  
  18.         searchRequest=GetXmlHttpObject();
  19.         searchRequest.onreadystatechange=function(){
  20.             searchReqChanged();
  21.         }
  22.         searchRequest.open("GET",url,true);
  23.         searchRequest.send(null);
  24.     getSorter(sess, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp);
  25. }
  26.  
  27. function searchReqChanged(){
  28.     if (searchRequest.readyState==4)
  29.     {     
  30.         repeatSort = 0;
  31.     }
  32. }
  33.  
  34.  
  35. function getSorter(sess, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp)
  36. {
  37.         var sesst= escape(encodeURI(sess));
  38.         var url="sorter2.php";
  39.         url=url+"?sid="+Math.random();
  40.         url=url+"&sesst="+sesst+"&sort="+sort+"&loc1="+loc1+"&loc2="+loc2+ "&loc3="+loc3+"&loc4="+loc4+"&loc5="+loc5+"&starslm="+starslm+ "&stars="+stars+"&minp="+minp+"&maxp="+maxp;
  41.         sorterRequest=GetXmlHttpObject();
  42.  
  43.         sorterRequest.onreadystatechange=function(){
  44.  
  45.             sorterReqChanged(sess, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp);
  46.         }
  47.  
  48.         sorterRequest.open("GET",url,true);
  49.         sorterRequest.send(null);
  50. }
  51.  
  52.  
  53. function sorterReqChanged(sess, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp){
  54.     if (sorterRequest.readyState==4)
  55.     { 
  56.         document.getElementById("results").innerHTML=sorterRequest.responseText;
  57.  
  58.         if (repeatSort != -1){
  59.             getSorter(sess, sort, loc1, loc2, loc3, loc4, loc5, starslm, stars, minp, maxp);
  60.  
  61.         }
  62.         if (repeatSort == -1){
  63.             var finished = 'Search Complete!';
  64.             document.getElementById("loading").innerHTML=finished;    
  65.         }
  66.         if (repeatSort == 0){
  67.             repeatSort = -1;
  68.         }
  69.     }
  70.  
  71. }
  72.  
  73. function GetXmlHttpObject()
  74. {
  75. var xmlHttp=null;
  76. try
  77.   {
  78.   // Firefox, Opera 8.0+, Safari
  79.   xmlHttp=new XMLHttpRequest();
  80.   }
  81. catch (e)
  82.   {
  83.   // Internet Explorer
  84.   try
  85.     {
  86.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  87.     }
  88.   catch (e)
  89.     {
  90.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  91.     }
  92.   }
  93. return xmlHttp;
  94. }
  95.  
  96.  
Jan 14 '08 #1
Share this Question
Share on Google+
1 Reply


kunal pawar
100+
P: 297
May be IE readystate will be "complete" rather than 4

Expand|Select|Wrap|Line Numbers
  1. function searchReqChanged(){
  2.     if (searchRequest.readyState==4 || searchRequest.readyState=="complete")
  3.     {   
  4.         repeatSort = 0;
  5.     }
  6. }
Jan 15 '08 #2

Post your reply

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