function getReportedInfo(id) {
$.ajax({
url: 'includes/get_data.php',
type: 'POST',
data: {id:id},
dataType: 'json',
success: function(data) {
console.log(data);
}
});
};
The JSON object returned from the get_data.php script is:
{
id: 5,
username: "Anthony",
status: "accupied"
}
I am able to the length of the data object if I do console.log(data.length). However, I can see the object when I console.log(data) in the success property. I am not able to access the elements of the data obejct if I do console.log(data.username), doing this displays undefined in the console. I created a variable, data1, outside the scope of the function getReportedInfo and assigned the data retrieved via the success property to this variable after I tried to display the constents of data1 outside the function.