$(function(){ var hotelcodes = []; $('.tripadvisor_reviews').map(function(){ hotelcodes.push($(this).data('hotelcode')); }); console.log(hotelcodes); if ( hotelcodes.length ){ $.ajax({ type: "POST", url: "https://stworld.jp/ta_api/get_reviews/", data: { hotelcodes: hotelcodes.join(",") }, dataType: "json", success: function ( j ){ $.each(j,function(idx,val){ $('[data-hotelcode="'+idx+'"]').show(); $('[data-hotelrating="'+idx+'"]').html(val.rating); $('[data-hotelratingimg="'+idx+'"]').attr("src",val.rating_image_url); $('[data-hotelurl="'+idx+'"]').attr("href",val.web_url); $('[data-hotelreviewnum="'+idx+'"]').html(String(val.num_reviews).replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,')); $.each(val.subratings,function(s,sr){ $('[data-hotel'+sr.name+'="'+idx+'"]').html(sr.value); $('[data-hotel'+sr.name+'_img="'+idx+'"]').attr("src",sr.rating_image_url); }); $('.ta_show').show(); }); } }); } });