I return an array of a customer's addresses with PHP via Ajax (return as addresses). I document.write the addresses.responseText which displays the array perfectly
Array ( [0] => Array ( [addressID] => 15804 [customerID] => 10 [loanID] => [address1] => 6 Road [address2] => [address3] => [town] => Their Town [county] => Their County [postCode] => Their postCode [reason] => [current] => 1 [timestamp] => 2013-03-13 14:41:39 ) [1] => Array ( [addressID] => 10 [customerID] => 10 [loanID] => [address1] => 21A Road [address2] => [address3] => [town] => Their 2nd Town [county] => Their 2nd County [postCode] => Their 2nd postCode [reason] => [current] => 0 [timestamp] => 2013-03-13 14:41:39 ) )
I'm having problem though with looping through and using the array information.
new Ajax.Request('includes/ajax.php',
{
method:'post',
parameters: {addCustID: customerID},
onSuccess: function(addresses){
document.write(addresses.responseText);
for (var i in addresses)
{
if(i == "responseText")
{
addressExpander.addEntry(addresses[i]);
}
}
},
onFailure: function(){ alert('Something went wrong...') }
});
I want to run addressExpander.addEntry(addresses[i]);
for each address, but it only displays once, not for each address.
I've tried looping through addresses.responseText
in the if(i == "responseText")
loop but it doesn't do anything.
I'm using Prototype by the way, it is already being used in the page.
if(i == "responseText")
forif(addresses[i] == "responseText")
otherwise you're comparing the index instead of the actual value of the variable. – Jeff Noel Aug 20 at 14:27addresses
hold the value"responseText"
. – Jeff Noel Aug 20 at 14:53