I have a probably quite simple to solve problem. I’m trying to parse this JSON file using jquery:
My jQuery code looks like that:
$.post("/xhr/fav_switch", {event_id: event_id}, function(data) {
event = jQuery.parseJSON(data);
alert(event.pk);
});
but no matter which field i’m trying to access in alert, it allways says undefined. have you any idea what am i doing wrong? Any help would be appreciated 🙂
You get an array (with one element) back, so event is an array. You need to get the first element of the array to get to the event object itself.