473,395 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Looping synchronous Ajax xmlhttp requests not refreshing in IE

11
Hi,

I have a loop in which I'm making Ajax xmlhttp requests. This occurs within a function triggered by a window.onload event.

The Ajax calls are being made with async=false, because they need to occur in a specific order that relies on each step completing before the next can occur.

With each successive request in the loop, I'm updating a div with the xmlhttp.responseText.

Firefox is refreshing between calls as desired.

IE is not. When the loop begins, the div is populated with the pre-loop content. When the loop finishes, the div is populated with the first refresh that occurs outside of the loop.

Can someone please help?

Two attempted solutions:
1. Adding a random string to the end of the GET query string to ensure a unique url
2. Submitting with the POST method

No luck with either.

Thanks.
Jul 25 '10 #1
22 4859
Dormilich
8,658 Expert Mod 8TB
I would need to see the code to make more than a guess.
Jul 25 '10 #2
Chris G
11
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function order_process() {
  3.         var err;
  4.         var queue_id = "<?= implode(':',$plans[$_REQUEST['order_queue_id']]); ?>".split(':');                // Queue ID
  5.         var queue_ax = "<?= implode(':',array_keys($plans[$_REQUEST['order_queue_id']])); ?>".split(':');    // Queue Action
  6.         i = 0;
  7.         for (step in queue_id) {
  8.  
  9.             // The DIV contents that display during each loop iteration
  10.             document.getElementById("barber_pole").innerHTML='\
  11.                 <center>\
  12.                 <table style="align:left" border="0" cellpacing="1" cellpadding="1">\
  13.                     <tr><td><B>Processing Order</B><span style="float:right;">Step ' + (i + 1) + '/' + queue_id.length + '</span></td></tr>\
  14.                     <tr><td style="background-color:#FFFFFF;height:1.5px"></td></tr>\
  15.                     <tr><td height="20" style="text-align:center">' + queue_ax[i] + '...</td></tr>\
  16.                     <tr><td height="20"><IMG SRC="http://bytes.com/topic/_include/images/barber_pole.gif" style="vertical-align: middle;"></td></tr>\
  17.                 </table>\
  18.                 </center>';
  19.  
  20.             xmlhttp = ajax_request(); // Create request object
  21.             xmlhttp.onreadystatechange=function () {
  22.                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  23.                     1;
  24.                 }
  25.             }
  26.  
  27.             var url = '../../../api/order_process.php?api_login=' + "<?=$api_login?>" + '&api_pass=' + "<?=$api_pass?>" + "&order_id=<?= $_REQUEST['order_id']?>" + '&order_action_id=' + queue_id[step] + '&timeid=' + Math.random();
  28.             xmlhttp.open("GET",url,false);
  29.             xmlhttp.send();
  30.  
  31.             // If the response includes the string 'failed' exit the loop and render error error message
  32.             if (xmlhttp.responseText.split(',')[0] == 'failed') {
  33.                 err = queue_ax[i] == 'Registering Domain'
  34.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[domain_register][title]?>"      + "</h1><DIV class='landing-body'><?=$feedback[domain_register][body]?></DIV>"
  35.                     : queue_ax[i] == 'Provisioning cPanel Account'
  36.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[cpanel_provision][title]?>"     + "</h1><DIV class='landing-body'><?=$feedback[cpanel_provision][body]?></DIV>"
  37.                     : queue_ax[i] == 'Credit Card Fraud Protection'
  38.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[maxmind_minfraud][title]?>"     + "</h1><DIV class='landing-body'><?=$feedback[maxmind_minfraud][body]?>\"" + xmlhttp.responseText + '"</DIV>'
  39.                     : queue_ax[i] == 'Verifying Payment'
  40.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[verify_payment][title]?>"       + "</h1><DIV class='landing-body'><?=$feedback[verify_payment][body]?>\""   + xmlhttp.responseText + '"</DIV>'
  41.                     : xmlhttp.responseText == 'failed,'
  42.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[gen_err][title]?>"              + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?></DIV>"
  43.                     : "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[gen_err][title]?>"              + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?>\""          + xmlhttp.responseText + '"</DIV>';
  44.                 break;
  45.             }
  46.             i++;
  47.         }
  48.  
  49.         if (err) {
  50.             document.getElementById("landing-pres").innerHTML = err;
  51.             Cufon.replace('.landing-title');
  52.         } else {
  53.             document.getElementById("barber_pole").innerHTML = "<?= $thank[$_REQUEST['order_queue_id']][1] ?>";
  54.         }
  55.     }
  56.     window.onload=order_process;
  57.     </script>
  58.  
Jul 25 '10 #3
Dormilich
8,658 Expert Mod 8TB
well, a for … in loop is not the suited structure to loop over an array, better use a standard for() loop.
Jul 25 '10 #4
Chris G
11
I made the change as you suggested and it made no difference...

Any other suggestions?

Thanks
Expand|Select|Wrap|Line Numbers
  1.     <script type="text/javascript">
  2.     function order_process() {
  3.         var err;
  4.         var queue_id = "<?= implode(':',$plans[$_REQUEST['order_queue_id']]); ?>".split(':');                // Queue ID
  5.         var queue_ax = "<?= implode(':',array_keys($plans[$_REQUEST['order_queue_id']])); ?>".split(':');    // Queue Action
  6.         for (i = 0; i < queue_id.length; i++) {
  7.             // The DIV contents that display during each loop iteration
  8.             document.getElementById("barber_pole").innerHTML='\
  9.                 <center>\
  10.                 <table style="align:left" border="0" cellpacing="1" cellpadding="1">\
  11.                     <tr><td><B>Processing Order</B><span style="float:right;">Step ' + (i + 1) + '/' + queue_id.length + '</span></td></tr>\
  12.                     <tr><td style="background-color:#FFFFFF;height:1.5px"></td></tr>\
  13.                     <tr><td height="20" style="text-align:center">' + queue_ax[i] + '...</td></tr>\
  14.                     <tr><td height="20"><IMG SRC="http://bytes.com/topic/_include/images/barber_pole.gif" style="vertical-align: middle;"></td></tr>\
  15.                 </table>\
  16.                 </center>';
  17.  
  18.             xmlhttp = ajax_request(); // Create request object
  19.             xmlhttp.onreadystatechange=function () {
  20.                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  21.                     1;
  22.                 }
  23.             }
  24.  
  25.             var url = '../../../api/order_process.php?api_login=' + "<?=$api_login?>" + '&api_pass=' + "<?=$api_pass?>" + "&order_id=<?= $_REQUEST['order_id']?>" + '&order_action_id=' + queue_id[i] + '&timeid=' + Math.random();
  26.             xmlhttp.open("GET",url,false);
  27.             xmlhttp.send();
  28.  
  29.             // If the response includes the string 'failed' exit the loop and render error error message
  30.             if (xmlhttp.responseText.split(',')[0] == 'failed') {
  31.                 err = queue_ax[i] == 'Registering Domain'
  32.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[domain_register][title]?>"      + "</h1><DIV class='landing-body'><?=$feedback[domain_register][body]?></DIV>"
  33.                     : queue_ax[i] == 'Provisioning cPanel Account'
  34.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[cpanel_provision][title]?>"     + "</h1><DIV class='landing-body'><?=$feedback[cpanel_provision][body]?></DIV>"
  35.                     : queue_ax[i] == 'Credit Card Fraud Protection'
  36.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[maxmind_minfraud][title]?>"     + "</h1><DIV class='landing-body'><?=$feedback[maxmind_minfraud][body]?>\"" + xmlhttp.responseText + '"</DIV>'
  37.                     : queue_ax[i] == 'Verifying Payment'
  38.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[verify_payment][title]?>"       + "</h1><DIV class='landing-body'><?=$feedback[verify_payment][body]?>\""   + xmlhttp.responseText + '"</DIV>'
  39.                     : xmlhttp.responseText == 'failed,'
  40.                     ? "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[gen_err][title]?>"              + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?></DIV>"
  41.                     : "<h1 class=\"landing-title\">"  + fname + ', ' + "<?=$feedback[gen_err][title]?>"              + "</h1><DIV class='landing-body'><?=$feedback[gen_err][body]?>\""          + xmlhttp.responseText + '"</DIV>';
  42.                 break;
  43.             }
  44.         }
  45.  
  46.         if (err) {
  47.             document.getElementById("landing-pres").innerHTML = err;
  48.             Cufon.replace('.landing-title');
  49.         } else {
  50.             document.getElementById("barber_pole").innerHTML = "<?= $thank[$_REQUEST['order_queue_id']][1] ?>";
  51.         }
  52.     }
  53.     window.onload=order_process;
  54.     </script>
  55.  
Jul 25 '10 #5
Dormilich
8,658 Expert Mod 8TB
what happens, if you replace the original multi-line assignment with a simple test string? (testing whether IE likes the backslash EOL)
Jul 25 '10 #6
Chris G
11
Thanks, Dormilich, i did try that earlier ...

Expand|Select|Wrap|Line Numbers
  1.             // The DIV contents that display during each loop iteration
  2.             document.getElementById("barber_pole").innerHTML='test' + i;
  3.  
... but it had no affect.

Still digging for an answer...

IE does not update anything until after the window.onload function finishes. The interesting thing is, if i stick an alert box in each iteration of the loop, the screen does refresh the div.
Jul 25 '10 #7
Chris G
11
Still looking for some guidance on this one...

Anyone?

Thanks
Jul 27 '10 #8
Dormilich
8,658 Expert Mod 8TB
what kind of element is "barber_pole"?
Jul 27 '10 #9
Chris G
11
It's a <div> located near the bottom of the document.
Expand|Select|Wrap|Line Numbers
  1.                         echo '<h1 class="landing-title">',$order->info[first],', thank you for your order!</h1>';
  2.                         echo '
  3.                             <DIV STYLE="overflow-y: auto; height:245px; border:0 #000000 solid; text-align: left;  padding: 2px">',
  4.                             $thank[$order->order_queue_id][0],
  5.                             '<div height="100%" id="barber_pole" style="margin-bottom:15px">
  6.                             <center>
  7.                             <table border="0" cellpacing="1" cellpadding="1">
  8.                                 <tr><td style="text-align:left"><B>Processing Order</B><span style="float:right;">Step 1/'.count($plans[$order->order_queue_id]).'</span></td></tr>
  9.                                 <tr><td style="background-color:#FFFFFF;height:1.5px"></td></tr>
  10.                                 <tr><td height="20" style="text-align:center">'.$cat_queue[0].'...</td></tr>
  11.                                 <tr><td height="20"><IMG SRC="http://bytes.com/topic/_include/images/barber_pole.gif" style="vertical-align: middle;"></td></tr>
  12.                             </table>
  13.                             </center>
  14.                             </div>',
  15.                             '</DIV>';
  16.  
Jul 27 '10 #10
@Chris G
In my experience, IE is much more finicky about its caching than Firefox, and sometimes something that works fine in Firefox can have unexpected results in IE, even erratic. Check your order_process.php and make sure it is setting the headers correctly (Cache-control: no-cache, no-store; Pragma: no-cache; Expires: some-date-in-past)
Jul 29 '10 #11
Chris G
11
tetrahedral,

Thanks for your reply. I believe I already tried that with no luck, but I'll attempt again to be sure.

I am appending a random value to the end of the query string, isn't this essentially the same as setting the cache properties in the headers?

Still struggling with it...

Thanks
Jul 30 '10 #12
Chris G
11
i added the following to my request with no change in results...

Expand|Select|Wrap|Line Numbers
  1.         var url = '../../../api/order_process.php?api_login=' + "<?=$api_login?>" + '&api_pass=' + "<?=$api_pass?>" + "&order_id=<?= $_REQUEST['order_id']?>" + '&order_action_id=' + queue_id[i] + '&timeid=' + Math.random();
  2.         xmlhttp.open("GET",url,false);
  3.         xmlhttp.setRequestHeader("Cache-Control", "no-cache, must-revalidate");
  4.         xmlhttp.setRequestHeader("Pragma", "no-cache");
  5.         xmlhttp.setRequestHeader("Expires", "Sat, 1 Jan 2005 00:00:00 GMT");
  6.         xmlhttp.send();
  7.  
All suggestions appreciated. This is driving me nuts....
Jul 30 '10 #13
@Chris G
The request headers are not what we're worried about here, so those setRequestHeader() calls aren't very helpful.

What you need to set (assuming that caching is causing the problem) are your reply headers, which can be done from the server that the requests are being sent to. So, in that php file that you are requesting in your xmlhttprequest object, at the very top of the data that is sent back to the browser, you need:

Expand|Select|Wrap|Line Numbers
  1. Header("Cache-control: no-cache, no-store, must-revalidate");
  2. Header("Pragma: no-cache");
  3. Header("Expires: -1");
Again, this is all assuming that caching is what is causing your issues here (although it is a good idea to always do this for dynamic content).
Jul 30 '10 #14
Chris G
11
tetrahedral,

thanks again for your attention to this. Much appreciated. The php file being requested is actually a call to a third party api function. I did use the xmlhttp.getAllResponseHeaders function to display the response headers and found that all the parameters you suggested were being set somehow by both IE8 and FF- not sure where, perhaps by default? See the attached image for the list of response headers.

Any other suggestions?

Again, thanks so much for your help so far...
Attached Images
File Type: jpg response_headers.jpg (67.8 KB, 255 views)
Jul 30 '10 #15
Well then it appears cacheing can be ruled out as a probable cause.

I noticed you're using window.onload. Are you sure that the div 'barber_pole' has been loaded when it tries to access it? If not, then it will just load in with the pre-loop content (as you said is happening). You might look into jQuery's .ready() function, which waits until all of the elements are ready before calling a function.

P.S. Switching to jQuery in my development for this stuff saved me a load of headaches in terms of cross-browser problems.
Jul 30 '10 #16
Chris G
11
tetrahedral,

I've tried experimenting with the .ready function but I'm not certain as to where it would be used...

Is it wrapped around where the ajax object is created and where the send occurs?

Thanks...
Jul 30 '10 #17
@Chris G
It's much less complicated than you think!

In place of:
Expand|Select|Wrap|Line Numbers
  1. window.onload=order_process;
Use:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(order_process);
  2. //Which is also the same as
  3. $(order_process);
Jul 30 '10 #18
Chris G
11
Thanks again, Tetrahedral.

I replaced the onload with the following...

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(order_process);
  2.  
And the results were the same as with the onload.

Eek...

Still pulling my hair out...
Jul 30 '10 #19
Do you have a javascript debugger installed?
Jul 30 '10 #20
I am also having the same problem. If I clear Temp Internet files, and reload, it will display the correct file. Every refresh/loop after that, only shows the initially loaded file. Even if I close the browser and reopen it, it still shows the 'cached' version.

I've added an "alert(xmlhttp.responseText);" and that too only shows the 'cached' version. It seems that IE looks for a cached version first, which is strange since in the .js file it starts a "NEW" request and I'm just having it "GET" a .txt file. Which would make me think that even if you add "no-cache" to your HTML/PHP file, the "no-cache" does not pertain to the XML get command. So, is there a way to do a FORCE get command?

I've been working on this for about 4 days now, and still no progress. Has anyone found a solution for this yet?

--John
Sep 25 '10 #21
gits
5,390 Expert Mod 4TB
try to add a unique querystring to the url before sending the request, like:

Expand|Select|Wrap|Line Numbers
  1. xmlhttprequest.open("GET", url + "?" + (+ new Date), false);
Sep 25 '10 #22
gits-

Thank you. I figured that out this morning (1:30am), then went to bed -- bald!
Sep 25 '10 #23

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

Similar topics

3
by: Tony | last post by:
I've done a fair bit of searching on this, but I want to be certain about what I've found - so here goes with a long example and three questions: For clarity, let me give an example (a number of...
1
by: peterlan | last post by:
Hello, I have an issue with a long-running import process in our asp.net app (1.1). After the user initiates an import, we're trying to make periodic xmlhttp requests to update a progress bar. In...
2
by: Prasad | last post by:
Hi all! I am trying to access a page through Synchronous Ajax request in mozilla firefox I could not get the response .. After the requset is sent , "onreadystatechange" function is not being...
2
by: dmagliola | last post by:
Hello all, I'm experiencing a problem with ASP.Net for which I can't find a reasonable explanation, or any information. I'm currently developing an application that, through AJAX, asks the...
2
by: Jay | last post by:
Getting into AJAX using the XMLHttp object and am really liking it. We are in the process of upgrading our existing behavior calls (webservice.htc) to the more 'supported', as they say, concept...
8
by: vunet | last post by:
I'd like to perform multiple XMLHTTP requests but one after the other, ie. do next when previous one comes back ok. Identifier to determine when to start the next one is a global variable whose...
3
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to...
7
by: Brent | last post by:
I'm trying to figure out how to iterate over an array that would send a series of XMLHttp requests. I'd like to have each request finish before the next one begins, but I believe that this is not...
10
dmjpro
by: dmjpro | last post by:
function synchronous_ajax(){ var ajax = null; if(typeof ActiveXObject!='undefined') ajax = new ActiveXObject("Microsoft.XMLHTTP"); else if(typeof XMLHttpRequest!='undefined') ajax = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.