I’m trying to parse a JSON response with jQuery but it’s not working.
This the response I’m getting from the server:
[{"id":4,"targetUser":2},{"id":5,"targetUser":2}]
What I want to do is append the targetUser and id to a #box:
$.get(cometQuery(), function(data){
var resp = jQuery.parseJSON(data);
$.each(data, function(key, val) {
$("#box").append(key + ": " + val);
});
});
The server is actually rendering a Java ArrayList, so there could be more than one record.
Any ideas what I’m doing wrong?
When you call
$.each(), you forgot to providerespinstead ofdata: