返回目标文件jquery ajax php的数组响应

am trying to populate fields automatically behalf of what user typed in particular input field. eg: i want to populate automatically username and age when someone type fullname, but trouble is when i receive data in array() i can only use it with single element either in age field or in username field, what i basically want is this ::

$.ajax({url: "/php/autofill.php?query="+query, success: function(result){
 $("#ajax").html(result);
}});

Can i just fetch that like below?

$.ajax({url: "/php/autofill.php?query="+query, success: function(result){
 $("#ajax").html(result.username);

//or

$("#ajax").html(result.age);
}});

i know code is too dirty, but i want to do it like this way anyhow, looking for answers