How do I append a range of JSON data to my HTML using Javascript or Jquery? -


What I am trying to do is to capture it from my JSON file. For example, my JSON data looks like this:

  {"Pictures": {"Painting": [{"Title": "Boardwalk 5", "Artist": "Ernie Palmer "A Piece of Piece", "Artist": "Arni Palmer", "Image": "AP2. JPG": "Ape 1. JPG", "Price": 850}, {"Title" , "Price": 450}, {"Headline": "Surf in High Tide", "Artist": "Arni Palmer", "Image": "AP3. JPG", "Price": 950}, {"Title ":" Games I want , "Artist": "Arni Palmer", "Image": "ap4.jpg", "price": 850}]}}  

& Lt; div class = "area1" Add the first 2 items in my JSON array to item 3 and 4

Here I have explained all my data How to pull:

  $ (document) .ready (function () {$ .ajax ({type: 'GET', url: 'data.json' data type: 'Jason' , Success: JasonAparser}}}; ​​function jsonParser (json) {$ ('# load'). FadeOut (); $ .getJSON ('data.json', function (data) {$ .each (Data PaintingsPanting, Function (K, V) {var title = V. Tetal; Var IMG = V.Image; Var value = v. Price; Here is the place where I need $ $ ('. Area 1'). Append ('
' + title + '
gt; + title + '
$' + price + '& lt; / div & gt; & Lt; / div & gt; ')});}); }

And here's my HTML:

  & lt; Body & gt; & Lt; Div class = "area1" & gt; ... The first half of JSON data is here ... & lt; / Div & gt; & Lt; Div class = "area 2" & gt; ... the second part of the JSON data here & lt; / Div & gt; & Lt; / Body & gt;  

Then a JSON file with data is broken, then added to two areas

  $ GetJSON ('data.json', function (data) {$ .each (data paintingpanting, function (K, v) {var title = v.title; var img = v.image; var value = v.price; var Regional ; Switch (k) {Case 0: Case 1: Regional = '.area1'; break; Case 2: Case 3: Regional = '.area2'; break;} $ (Regional) .append ('& lt; div class = "Painting" & gt; & lt; img src = "images / '+ img +'" width = "200" height = "225" alt = "'+ title +'" /> gt; & lt; br / & Gt; & lt; div class = "title" & gt; '+ title +' 
$ '+ price +' & lt; / div & gt; & lt; / div & gt; ')});});

or even more scalable

  $ GetJSON ('data.json', function (data) {$ .each (data paintingpanting, function (k, v) {var title = v.title; var img = v.image; Var value = v. Prix; // We add the area by adding between 1 and 1 of 1 to 1 and 1 to 1, and from 10 to 1, the key of 1, 1 goes to 2, that is, 2 means var area = '.' Era '(Math. K / 10) + 1); $ (regional) .append ('div class = "painting"> '+ title +' div class = "title"> gt; + title +' 

price + '& Lt; / div & gt; & lt; / div & gt;')});});


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -