Ajax 経由で PHP を使用して顧客の住所の配列を返します (住所として返す)。配列を完全に表示するaddresses.responseTextをdocument.writeします
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 ) )
配列情報をループして使用することに問題があります。
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...') }
});
アドレスごとに実行したいのですaddressExpander.addEntry(addresses[i]);
が、アドレスごとではなく一度しか表示されません。
addresses.responseText
ループ内をループしようとしましたif(i == "responseText")
が、何もしません。
ちなみにPrototypeを使っていますが、すでにページ内で使われています。