I seem to have trouble with getting data from a php array, I've looked at various examples of how to do this but I must be missing something because I can not get my code to work.
PHP method
function getLatestActivity(){
$messages = array(
array('id'=>'01', 'value'=>'blah'),
array('id'=>'02', 'value'=>'Oil'),
array('id'=>'03', 'value'=>'Spark')
);
echo json_encode($messages);
return;
}
AJAX get functiom
function getLatestActivities(){
$.ajax({
type: "GET", url: "include/process.php",
data:{
getLatestActivity: "true",
toUser: "4",
ignoreMessages:"1",
dataType: "json"
},
success: function(data){
$.each(data, function (i, elem) {
alert(data.id);
});
}
});
}
The alert prints out the message "undefined", any help would be appreciated thank you.