Can't access dojo object property using string variable
- by Kareem
I am retrieving a json associative array using a dojo xhrGet request. The data comes back just fine, however I need the app to be able to display the keys and their properties (or values) without knowing the keys beforehand. So, I do the following:
function getData() {
dojo.xhrGet( {
url: "ytd_process.php",
handleAs: "json",
load: function(response) {
for (var key in response) {
dojo.byId("boxes").innerHTML+="<div id=\"box\">"+key+":"+response.key+"</div>";
}
console.dir(response); // Dump it to the console
}
});
};
The keys are retrieved and displayed on the page, but the response.key returns undefined. I know the syntax is correct because if I replace .key with an actual key value it will display correctly. It appears it doesn't like a string as the key. Any help or advice would be greatly appreciated. Thank you.