I created json with php. Data coming with ajax. But JSON.parse is giving an “undefined” object. Why ?
Php CODE
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);
Ajax CODE
$.ajax({
type: "GET",
url: "http://localhost:8080/xxx.php/",
success: function (msg, result, status, xhr) {
var obj= JSON.parse(msg);
alert(obj.name);// giving undefined
},
error: function (error) {
}
});
json
[{"name":"eng","a":"sdf"}]