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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.