I have a example.json
file like this:
{
"User1": [{
"Age":21,
"Dogs":5,
"Cats":0
}],
"User2": [{
"Age":19,
"Dogs":2,
"Cats":1
}]
"User3": [ ...and so on...]
}
and a function LoadData(UserName);
like this:
LoadData(UserName) {
$.ajax({
url: "/users/example.json",
dataType: "json",
data: // How can i say to AJAX to parse only the UserName array?
success: function(response) {
var data = $.parseJSON(response);
$.("#ageID").text(response.Age);
$.("#dogsID").text(response.Dogs);
// And so on with the others fields
}
});
}
Also.. the function LoadData(UserName);
is called by the main html file (actually a .php script) with something like this:
<head>
<script type="text/javascript">
$(document).ready(function() {
LoadData("<?php echo $_SESSION['user_name']; ?>");
});
</script>
</head>
Thanks!
NOTE: i perfectly know that all data i parse/use in this way will be perfectly visible to anyone. The example above is just, indeed, an example. The data i am dealing with is not private, rather is actually public.