I received a JSON object through an AJAX request.
When I use console.log(response); in the console, I can see my object. However, when I use
console.log(response.mostSearched);
, it returns undefined
. Why is that?
I copied the object from the devTools console and placed it into my JavaScript code like this: var obj = {...etc};
. Then I used console.log(obj.mostSearched);
and it worked perfectly.
What am I missing that prevents it from working with console.log(response);
?
My Ajax request:
var req = new Request({
method: 'post',
url: stats_ajax_cal,
data: {
'itemSelect': itemSelect,
'type_of_graph': type_of_graph,
'dateFrom': dateFrom,
'dateTo': dateTo,
},
onSuccess: function(response) {
console.log(response); // looks good
var obj = response;
console.log('***');
console.log(obj); // looks good
console.log(obj.mostSearched); // undefined
}
}).send();
My object:
{
"mostSearched": {
"title": "Most serached houses",
"colNames": [],
"rowNames": {
"21": 1,
"10": 2,
"76": 1,
"20": 1,
"23": 1,
"13": 3,
"18": 1
}
},
"timeOfDay": "",
"averagePrice": 5904.8,
"averageDuration": 0.6,
"searchedDays": {
"2013-12-21": 1,
"2013-12-22": 1,
"2013-12-23": 1,
"2013-12-24": 1,
"2013-12-25": 1,
"2013-12-26": 1,
"2013-12-27": 1,
"2013-11-16": 2,
"2013-11-17": 2,
"2013-11-18": 2,
"2013-11-19": 2,
"2013-11-20": 2,
"2013-11-21": 2,
"2013-11-22": 2,
"2013-11-23": 2,
"2013-11-24": 2,
"2013-11-25": 2,
"2013-11-26": 2,
"2013-11-27": 2,
"2013-11-28": 2,
"2013-11-29": 2,
"2013-09-06": 4,
"2013-09-07": 4,
"2013-09-08": 4,
"2013-09-09": 4,
"2013-09-10": 4,
"2013-09-11": 4,
"2013-09-12": 1,
"2013-10-07": 3,
"2013-10-08": 3,
"2013-10-09": 3,
"2013-10-10": 3,
"2013-10-11": 3,
"2013-10-12": 3
}
}