Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed Some Help Parsing JSON with JQuery
    text
    copied!<p>I'm trying to parse a JSON document with JQuery, but things just aren't going my way. The feed I want to access is located at "<em>http://marketplace.envato.com/api/edge/new-files-from-user:collins,themeforest.json</em>," and here is the return result:</p> <pre><code>{ "new-files-from-user":[ { "thumbnail":"http://3.s3.envato.com/files/60560.jpg", "tags":"", "user":"collis", "url":"http://themeforest.net/item/manilla-photoshop-design/22803", "live_preview_url":"http://2.s3.envato.com/files/60561/1_Home.__large_preview.jpg", "uploaded_on":"Wed Dec 03 03:32:35 +1100 2008", "cost":"10.00", "item":"Manilla Photoshop Design", "sales":"294", "rating":"4", "id":"22803" }, { "thumbnail":"http://2.s3.envato.com/files/60223.jpg", "tags":"clean", "user":"collis", "url":"http://themeforest.net/item/black-white-simple-theme/22705", "live_preview_url":"http://0.s3.envato.com/files/60224/1_home.__large_preview.jpg", "uploaded_on":"Tue Dec 02 04:01:12 +1100 2008", "cost":"8.00","item":"Black + White Simple Theme", "sales":"272"," rating":"4", "id":"22705" }, { "thumbnail":"http://1.s3.envato.com/files/44556.jpg", "tags":"clean", "user":"collis", "url":"http://themeforest.net/item/quik-v1-admin-skin/17314", "live_preview_url":"http://3.s3.envato.com/files/44557/1_green.__large_preview.jpg", "uploaded_on":"Fri Sep 05 07:30:24 +1000 2008","cost":"12.00", "item":"Quik v1 Admin Skin", "sales":"336", "rating":"5", "id":"17314" }, {"thumbnail":"http://3.s3.envato.com/files/45212.jpg", "tags":"clean", "user":"collis", "url":"http://themeforest.net/item/freshcorp-business-template/17528", "live_preview_url":"http://3.s3.envato.com/files/45213/1_Homepage.__large_preview.jpg", "uploaded_on":"Tue Sep 09 06:10:50 +1000 2008", "cost":"20.00", "item":"FreshCorp - Business Template", "sales":"277", "rating":"4","id":"17528" }, {"thumbnail":"http://0.s3.envato.com/files/45739.jpg", "tags":"clean", "user":"collis", "url":"http://themeforest.net/item/real-estate-html-template/17732", "live_preview_url":"http://0.s3.envato.com/files/45740/1_homepage.__large_preview.jpg", "uploaded_on":"Fri Sep 12 14:22:45 +1000 2008", "cost":"20.00","item":"Real Estate HTML Template", "sales":"175", "rating":"4", "id":"17732" } ] } </code></pre> <p>I found a premade script that creates a table and adds the JSON items to it (below) but what I'd really like to do is just create my own div with perhaps the image, with the title and a link to the item. I've tried countless tutorials and have also read the JQuery API, I just can't seem to get it to work. Can anyone help me?</p> <pre><code>&lt;table id="userdata" border="1"&gt; &lt;thead&gt; &lt;th&gt;Thumbnail URL&lt;/th&gt; &lt;th&gt;Item URL&lt;/th&gt; &lt;th&gt;Cost&lt;/th&gt; &lt;th&gt;Number of Sales&lt;/th&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;script&gt; $(document).ready(function(){ $.getJSON( "http://marketplace.envato.com/api/edge/new-files-from-user:collins,themeforest.json", function(data){ $.each(data.new-files-from-user, function(i,user){ var tblRow = "&lt;tr&gt;" +"&lt;td&gt;"+user.thumbnail+"&lt;/td&gt;" +"&lt;td&gt;"+user.url+"&lt;/td&gt;" +"&lt;td&gt;"+user.cost+"&lt;/td&gt;" +"&lt;td&gt;"+user.sales+"&lt;/td&gt;" +"&lt;/tr&gt;" $(tblRow).appendTo("#userdata tbody"); }); } ); }); &lt;/script&gt; </code></pre>
 

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