I'm using json_encode to convert an associative array to JSON format. But When I try to print the property of data accessed through Ajax from this PHP file, it shows undefined. When I checked the type of data, it returns string.
$elem1= "<div class='menuitems'>
<div class='menu1'>".$row['name']."<span class='srno'>".$row['srno']."</span></div>
<div class='menu2'>".$row['email']."</div>
<div class='menu3'>".$row['password']."<span class='cross'>X</span></div>
<div class='clear'></div>
</div>";
$elem2=$row['category'];
$array=array(
"elem1"=>"$elem1",
"elem2"=>"$elem2"
);
echo json_encode($array);
Why is it so? How can I access the elem1 and elem2 through this string?
json_decode()to decode it.