Note that there are some explanatory texts on larger screens.

plurals
  1. POFiring other JavaScripts before AJAX in Chrome / IE
    primarykey
    data
    text
    <p><strong>My Problem:</strong> I've got this AJAX call inside of my Website that loads some content into a given DIV. While loading this content, a GIF loading animation gets inserted (via JavaScript), until AJAX returns the requested content. </p> <p>Wich works perfectly fine inside of Firefox, because FF loads the JavaScript in a linear order. Chrome and IE on the other hand do not seem to play that game. It seems that they're firing all AJAX first, then handling everything else.</p> <p><strong>Nice to know:</strong> The async on my AJAX call is FALSE. Yes I know, I should aim for the use of a TRUE async but in this case it just has to be that way. </p> <p><strong>My Goal:</strong> Since I know I can't do anything while my AJAX is loading, I would like to execute the line of code that inserst my animation BEFORE any AJAX gets called. I tried a setTimeout() but that just breaks the whole script.</p> <p>Any suggestions?</p> <p><strong>Here's the code:</strong></p> <pre><code>&lt;div id="mycolumn"&gt; &lt;!-- Here: Loading Animation first, then AJAX responseText --&gt; &lt;/div&gt; </code></pre> <p>JavaScript Function: </p> <pre><code>function myAjaxCall () { // Initiate HTTP Request if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } // I want this to happen BEFORE any AJAX gets executed document.getElementById("mycolumn").innerHTML="&lt;img src='loading.gif'&gt;"; // AJAX Request, gets fired by Chrome and IE before anything else, // wich prevents my img from being inserted before the response arrives xmlhttp.open("GET","someURL",false); xmlhttp.send(null); // AJAX Response, replaces my Loading Animation document.getElementById("mycolumn").innerHTML=xmlhttp.responseText; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload