I’m creating the JSON string in PHP, and using AJAX to fetch it.
<?php
// for loop {
$contacts[] = array(
'firstname' => $contact->getFname(),
'lastname' => $contact->getLname(),
'address' => $contact->getAddress(),
'city' => $contact->getCity(),
'postcode' => $contact->getPostcode()
);
// } end for loop
$arr = array('success' => 'yes', 'con' => $contacts);
echo json_encode($arr);
exit;
?>
I am not able to iterate a JSON string in Javascript. I have tried using the for loop, but I’m unable to get the results
for(var i = 0; i < data.con.length; i++) {
alert(d[i]);
}
I want to iterate through each con array in Ajax success function. My code is not working.
Shouldn’t this:
be something like this: