从数据库查询中,我得到一条返回字段/值的记录并将其放入数组中:
$arr = array();
while ($rowSearchZipCode = mysqli_fetch_array($resultSearchZipCode, MYSQLI_ASSOC)) {
$arr[] = $rowSearchZipCode;
}
我通过 php 脚本的回显将其发送回 jQuery ajax 调用:
echo print_r($arr);
在 $.ajax 的成功参数中的警告框中显示该数组表明我得到了一个如下所示的多维数组:
Array
(
[0] => Array
(
[id] => 55
[branchName] => SBN - Some Branch Name
[branchAddress1] => 1234 Elm St.
[branchAddress2] => Suite 000
[branchAddressCity] => Anywhere
[branchAddressState] => CA
[branchAddressZip] => 55000
[branchAddressPhone] => 555-555-5555
[branchAddressFax] => 555-555-4444
)
)
1
问题 1:我是否在 while 循环中正确构建了数组?
问题 2:在 $.ajax 调用中,如何从数组中获取字段/值对,以便将它们输出到 HTML 标记等?