Note that there are some explanatory texts on larger screens.

plurals
  1. POjson query for each item [number] in a loop
    text
    copied!<p>I have a two loops: one to count objects from a page, and other to set to each object a variable. let's say x is the number of objects and y the variables; so eg.: </p> <p><code>for x=10 ; y=3</code>loop shold look like:</p> <pre><code> x:y 1:1 2:2 [..] 8:2 9:3 10:1 </code></pre> <p>For each object I need to make a json query. Json will reply with 0/1 meaning query was/was not successful, and if the response fails, the query has to ignore the y var: eg.:</p> <pre><code>x:y 1:1 //1 2:2 //1 3:3 //0 - this is the failed query 4:1 //1 5:2 //1 6:1 //1 - y !=3 cause of failed query </code></pre> <p>......</p> <pre><code> $('button.#start').click(function(){ var last = $('input.blue').length; var totalpackages = '10'; var currentpackage; for( currentpackage = '1'; currentpackage &lt;= totalpackages; ) {// for each package; var n; for(n='1'; n &lt;= last;) { //alert(currentpackage + ' : ' + n) //n++ //currentpackage++ $.getJSON('api/testsenderfail.php', function(data){ worklink = data.data; if(worklink == '1') { alert(currentpackage + ' : ' + n + ' : ' + worklink) n++ currentpackage++ }else{ alert(currentpackage + ' : ' + n + ' : ' + worklink) n++ //currentpackage++ } }); } } }) </code></pre> <p>I am sure I did somethink wrong. Mozzila alerts "A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete."</p> <p>Php script "api/testsenderfail.php" generates json array and outputs {"data":"1"} (0/1) 90% outputs 1 and 10% outputs 0. This is for testing purposes.</p> <pre><code>&lt;?php $rand = rand(0, 9); if($rand == '0'){$work = '0';}else{$work = '1';} $data = array('data' =&gt; $work); echo json_encode($data); ?&gt; </code></pre>
 

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