Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax function hangs on loop
    primarykey
    data
    text
    <p>I have a little script in a html page that loops through an array, it runs an ajax function to check if a file is there, if it is..it prints a number off the array; if not it prints 0. The problem is that it just hangs (browser just sits there loading forever) after the first iteration. Is there a way to close the connection? I'm rather new to Ajax, so thanks for the help.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var cnt = 0; var getNum; var num = [25, 15, 24, 16, 23, 17, 22, 18, 21, 19, 20]; var response = 1; function getAjax(sales, cnt, getNum){ loadDoc(response); if(response == 1 ) { if(cnt &gt;= 11) { cnt = 0; } else { cnt++; } getNum = num[cnt]; } else{ getNum = 0; } document.write(getNum + '&lt;br/&gt;'); } function loadDoc(response) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { response = 1; } else { response = 0; } } xmlhttp.open("GET","randomFile.js",true); xmlhttp.send(); } function runIt(num, cnt, getNum, response){ setTimeout('getAjax(num, cnt, getNum)', 3000); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="alert"&gt;&lt;/div&gt; &lt;button type="button" onclick="runIt(num, cnt, getNum, response)"&gt;Change Content&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
 

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