我通过 Ajax 使用 PHP 返回一个客户地址数组(作为地址返回)。我 document.write 完美显示数组的addresses.responseText
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,它已经在页面中使用。