Jump to content

Alerting array index numbers rather than every character sent back


galvin

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.