Can't access dojo object property using string variable
Posted
by Kareem
on Stack Overflow
See other posts from Stack Overflow
or by Kareem
Published on 2009-07-22T14:07:52Z
Indexed on
2010/03/17
21:01 UTC
Read the original article
Hit count: 345
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.
© Stack Overflow or respective owner