how to get the content of JSON and put it in each html tags -
how to get the content of JSON and put it in each html tags -
newbie here, needs help.
the content right static, want them dynamic, want content json script below , set on each heading , div.
here json xml content.
<script type="text/javascript"> var info = { "items": { "phone" : [ { "product" : "iphone 8", "manufacturer" : "apple", "releasedate" : "2018", "price" : 35000 }, { "product" : "galaxy s9", "manufacturer" : "samsung", "releasedate" : "2018", "price" : 33000 }, { "product" : "xperia zz", "manufacturer" : "sony", "releasedate" : "2020", "price" : 35000 } ], "laptop" : [ { "product" : "macbook pro 2018", "manufacturer" : "apple", "releasedate" : "2017", "price" : 75000 }, { "product" : "vaio", "manufacturer" : "sony", "releasedate" : "2020", "price" : 73000 } ] } }; // render items in info using jquery $(document).ready(function() { }); // render items in info using native javascript function load() { } </script>
here div content static:
<h2>phones</h2> <div> <h3>iphone 8</h3> <p>manufactured apple, released in 2018</p> <form name="" method="post" action=""> <button type="submit">$35000</button> </form> </div> <div> <h3>galaxy s9</h3> <p>manufactured samsung, released in 2018</p> <form name="" method="post" action=""> <button type="submit">$33000</button> </form> </div> <div> <h3>xperia zz</h3> <p>manufactured sony, released in 2020</p> <form name="" method="post" action=""> <button type="submit">$35000</button> </form> </div> <h2>laptop</h2> <div> <h3>macbook pro 2018</h3> <p>manufactured apple, released in 2017</p> <form name="" method="post" action=""> <button type="submit">$75000</button> </form> </div> <div> <h3>vaio</h3> <p>manufactured sony, released in 2020</p> <form name="" method="post" action=""> <button type="submit">$73000</button> </form> </div> thanks!
deserialize json , iterate "for" loop. should this:
var deserializedinfo = json.parse(info); (var item in deserializedinfo.items) { (var product in item) { var producthtml = ""; producthtml .= "<div>"; producthtml .= "<h3>" + product['product'] + "</h3>"; producthtml .= "<p>" + product['manufacturer'] + "</p>"; producthtml .= "<p>" + product['releasedate'] + "</p>"; producthtml .= "<form name='' method='post' action=''>"; producthtml .= "<button>" + product['price'] + "</button>"; producthtml .= "</form>"; producthtml .= "</div>"; homecoming producthtml; //or whatever need } }
json
Comments
Post a Comment