get json information into html control with javascript

Solutions on MaxInterview for get json information into html control with javascript by the best coders in the world

showing results for - "get json information into html control with javascript"
Dario
08 Jul 2016
1/* I put your JSON into an external file, loaded from github */
2var url = "https://raw.githubusercontent.com/mspanish/playground/master/jessica.json";
3
4/* this tells the page to wait until jQuery has loaded, so you can use the Ajax call */
5
6$(document).ready(function(){
7  $.ajax({
8    url: url,
9    dataType: 'json',
10      error: function(){
11        console.log('JSON FAILED for data');
12      },
13    success:function(results){
14  /* the results is your json, you can reference the elements directly by using it here, without creating any additional variables */
15  
16      var cartItemsList = document.getElementById("cartItemsList");
17
18      results.basket.productList.forEach(function(element) {
19      cartItemsList.insertAdjacentHTML( 'beforeend',"<li>" +              element.product.name + " : " + element.price+ " </li>");
20      }); // end of forEach
21    }  // end of success fn
22   }) // end of Ajax call
23 }) // end of $(document).ready() function