I get a JSON Object from my PHP:
{
"Data":{
"Recipes":{
"Recipe_7":{
"ID":"7",
"TITLE":"Wurstel"
},
"Recipe_43":{
"ID":"43",
"TITLE":"Wurstel2"
}
}
},
"Message":null,
"Code":200
}
and i want to parse it in JS to get the id and the title
My Code:
var obj = jQuery.parseJSON(xmlhttp.responseText);
$.each(obj, function(){
document.getElementById("txtHint").innerHTML = this.recipes.toString();
});
The problem is that i always get UNDEFINED
My Quest:
How to parse the obj to get the titel and the id of each Recipe
As you’re already using the jQuery library, you might want to look at using the AJAX module in jQuery. It stops you worrying about the browser differences (
XMLHttpRequestvsActiveX) etc.You can then use the
.getJSON()method, and you’ll receive a parsed response for you, making things slightly easier:If you’re adament you want to use jQuery.each, replace:
with:
Be vary aware that JavaScript is case sensitive;
DATA !== DataandID != id.