galvin Posted November 9, 2011 Share Posted November 9, 2011 I have this ajax code below which is getting data sent back from updateDB.php... <script type="text/javascript"> $(document).ready(function(){ $(function() { $("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() { var order = $(this).sortable("serialize") + '&action=updateRecordsListings'; $.post("updateDB.php", order, function(theResponse){ $("#contentRight").html(theResponse); //line 1 renumber(theResponse); //line 2 }); } }); }); }); </script> updateDB.php is sending back an array with this... print_r($updateRecordsArray); And that data looks like this in the "contentRight" div because of the commented "line 1" above... Array ( [0] => 1 [1] => 9 [2] => 10 [3] => 7 [4] => 8 [5] => 4 [6] => 2 [7] => 3 [8] => 6 [9] => 5 ) Commented "line 2" above runs this code below. My goal is to have it alert "0", then alert "1", then alert "2" and so on for as big as the array is. However, this code below is alerting every single character in the array, i.e. it alerts "A", then alerts "r", then alerts "r", then alerts a", then alerts "y", then alerts a space, then alerts "(" and so on. How do I get it to just alert the index numbers? (which is 0-9 in this case) <script> function renumber(val) { var myStringArray = val; for (var i = 0; i < myStringArray.length; i++) { alert(myStringArray[i]); } } </script> Link to comment https://forums.phpfreaks.com/topic/250749-alerting-array-index-numbers-rather-than-every-character-sent-back/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.