aherrick aherrick - 8 months ago 34
JSON Question

jQuery loop over JSON result from AJAX Success?

On the jQuery AJAX success callback I want to loop over the results of the object. This is an example of how the response looks in Firebug.


How can I loop over the results so that I would have access to each of the elements?
I have tried something like below but this does not seem to be working.

jQuery.each(data, function(index, itemData) {
// itemData.TEST1
// itemData.TEST2
// itemData.TEST3


you can remove the outer loop and replace this with data.data:

$.each(data.data, function(k, v) {
    /// do stuff

You were close:

$.each(data, function() {
  $.each(this, function(k, v) {
    /// do stuff

You have an array of objects/maps so the outer loop iterates over those. The inner loop iterates over the properties on each object element.