html - jquery ajax success not finding variable div -


i have following code:

<script> function initialdata() {     var patches = [<?php echo $jspatcharray ?>];      (i = 0; < patches.length; i++) {          var dividpatch = "\"#initialdata-" +patches[i]+ "\"";             $.ajax({             type: "get",             url: "initial_data.php",             data: {patch:patches[i]},             success: function( data ) {                 $( dividpatch ).html( data );             }         });       };       var dividcount = "#srcount";      $.ajax({         type: "get",         url: "sr_count.php",         success: function( data ) {             $( dividcount ).html( data );          }     });  } </script>  <?php $_session['patchobjs'] = array();  foreach ($arrayrelqa $patch) {     echo "\n";     echo '<div id="initialdata-'.$patch.'"></div>'; } echo "\n<div id=\"srcount\"></div>"; 

from above part works fine:

var dividcount = "#srcount";  $.ajax({     type: "get",     url: "sr_count.php",     success: function( data ) {         $( dividcount ).html( data );      } }); 

however loop section not - ajax , underlying initial_data.php being executed success not finding div (dividpatch). must how i'm constructing var dividpatch. i've tried following (and various other variants:

var dividpatch = "\"#initialdata-" +patches[i]+ "\"";    var dividpatch = "#initialdata-" +patches[i];; 

subsequent investigation / edit

it looks ajax messing loop:

for (i = 0; < patches.length; i++) {      var patch = patches[i];     var dividpatch = "#initialdata-" +patches[i];       alert("outside: "+patch );     alert( "outside: "+dividpatch );              $.ajax({          type: "get",         url: "initial_data.php",         data: {patch:patch},         success: function( data ) {              alert( "inside div: "+dividpatch);             alert( "inside data: "+data);             $( dividpatch ).html( data );         }     });   }; 

the alerts fire in order (3 pacthes in array) note patch order on 'inside div' alert:

outside: patch 1 outside: #initialdata-patch 1 inside div: #initialdata-patch 2 inside data: patch 1 complete.  outside: patch 2 outside: #initialdata-patch 2 inside div: #initialdata-patch 3 inside data: patch 2 complete.  outside: patch 3 outside: #initialdata-patch 3 inside div: #initialdata-patch 3 inside data: patch 3 complete. 

this line:

  var dividpatch = "\"#initialdata-" +patches[i]+ "\"";  

should be:

var dividpatch = "#initialdata-" +patches[i];  

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -