Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing looped json data (Ajax)
    primarykey
    data
    text
    <p>In the data sample below, I'm trying to loop through and grab al data from the <code>participants</code> section. </p> <p>Through an ajax call I'm able to access the other data as follows, but I can't figure out the for statement for this data.</p> <pre><code>var userData = $.ajax({ type: "POST", url: userurl, dataType: "json", //data: { point: point, claimId: id, type: val,follow: followuser } }) .success(function(json) { $.each(json.data, function(i,x){ var id = x.Claim.user_id; // ETC ... </code></pre> <p>This works great. Using this format, I can access individual data like this: <code>x.participants[8].user_id</code>. I just can't figure out how to loop <code>participants</code> to grab all participant user_ids, for example.</p> <pre><code>{ "data": [ { "Claim": { "img_url": null, "id": "4", "user_id": "3", "claim_status": "started", "exp": "Sep 30, 2013" }, "User": { "score": "0", "id": "3" }, "ClaimResponse": [ { "id": "32", "claim_id": "4", "user_id": "14", "created": "2013-06-10 03:18:35", "modified": "2013-06-10 03:18:35" }, { "id": "107", "claim_id": "4", "user_id": "8", "created": "2013-06-28 02:37:10", "modified": "2013-06-28 02:37:10" }, { "id": "140", "claim_id": "4", "user_id": "976", "created": "2013-06-28 04:19:22", "modified": "2013-06-28 04:19:22" }, { "id": "152", "claim_id": "4", "user_id": "19", "created": "2013-07-03 02:27:12", "modified": "2013-07-03 02:27:12" }, { "id": "154", "claim_id": "4", "user_id": "1158", "created": "2013-07-05 03:16:48", "modified": "2013-07-05 03:16:48" } ], "participants": { "14": { "user_id": "14", "twitter_image_url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png" }, "8": { "user_id": "8", "twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_3_normal.png" }, "19": { "user_id": "19", "twitter_image_url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png" }, "1158": { "user_id": "1158", "twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png" } }, "viewer": { "isResponsed": false, "isOwner": false, "lockedInPoint": 0, "response": null, "cut_loss": false, "cut_loss_price": null } }, { "Claim": { "img_url": null, "id": "133", "user_id": "14", "claim_status": "started", "exp": "Jul 15, 2013" }, "User": { "score": "-40", "id": "14" }, "ClaimResponse": [ { "id": "172", "claim_id": "133", "user_id": "8", "created": "2013-07-12 20:36:16", "modified": "2013-07-12 20:36:16" }, { "id": "176", "claim_id": "133", "user_id": "1159", "created": "2013-07-13 02:52:31", "modified": "2013-07-13 02:52:31" } ], "participants": { "8": { "user_id": "8", "twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png" }, "1159": { "user_id": "1159", "twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png" } }, "viewer": { "isResponsed": false, "isOwner": false, "lockedInPoint": 0, "response": null, "cut_loss": false, "cut_loss_price": null } } ], "errors": [], "success": true, "code": 200 } </code></pre> <p><strong>EDIT:</strong> A fiddle, thanks to the help of @ohgodwhy. Maybe this better illustrates what I'm trying to do. I'd like the participant icons associated with their respective claim. It's close, but seems to be pulling in all the participants from the first claim...:</p> <p><a href="http://jsfiddle.net/gkGP4/5/" rel="nofollow">http://jsfiddle.net/gkGP4/5/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload