javascript - getJSON - append Images array -


i want display data json file through ajax request. display every data value except array of images. wrong? here json:

{ "item": {     "name": "abito corto",     "details": "maglia leggera, collo v, interno semi-foderato, logo.",     "composition": "composizione: 94% viscosa, 6% elastam.",     "modeldetails": [         "la modella indossa una taglia 40",         "misure: 86 - 60 - 90",         "altezza modella: 178cm"     ],     "images": [         "http://cdn.yoox.biz/34/34295573it_12n_f.jpg",         "http://cdn.yoox.biz/34/34295573it_12n_r.jpg",         "http://cdn.yoox.biz/34/34295573it_12n_e.jpg",         "http://cdn.yoox.biz/34/34295573it_12n_d.jpg"               ]        } } 

html:

<!doctype html> <html> <head>     <meta charset="utf-8">     <meta http-equiv="x-ua-compatible" content="ie=edge"> </head> <body>    <button id="driver">one</button>   <div class="news_details_container">   <img src="" alt="" >   </div>    </body>   </html> 

script:

$("#driver").click( function() {             $.getjson( "assets/data/one.json", function(data) {              $.each(data, function(key, value) {              $(".news_details_container").append(value.name);             $(".news_details_container").append(value.details);             $(".news_details_container").append(value.coposition );             $(".news_details_container").append(value.modeldetails);             $(".news_details_container").append('<img src="' + value.images + '" />');             });      }); }); 

i'm new ajax+ json. can me? thanks.

you have array of img src need loop display all

try:

    $("#driver").click( function() {            $.getjson( "assets/data/one.json", function(data) {                $.each(data, function(key, value) {                  $(".news_details_container").append(value.name);                 $(".news_details_container").append(value.details);                 $(".news_details_container").append(value.coposition );                 $(".news_details_container").append(value.modeldetails);                 $.each(value.images, function(i, v) {                 $(".news_details_container").append('<img src="' + v+ '" />');                 });              });           });    }); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -