I've done something like so
PHP
$returndata[$num] = array(
'type' => $num,
'id'=>$desc['id'],
'title' => $desc['title'],
);
json_encode($returndata);
AJAX
success: function(data){
var arr = data;
for (i in arr)
{
console.log(arr[i].title);
}
}
ALSO Tried
success: function(data){
$.each(data, function(i, val){
console.log(val.title);
});
}
I have the following JSON that i would like to put in separate var to use in HTML.
{
"5" :
{
"type":"5",
"id":"590",
"title":"Little Lamb"
}
"7" :
{
"type" : "7",
"id":"540",
"title":"Little Lamb 2"
}
}
But I can't get the titles.
dataType:'json'in your ajax call, I think you are missing that