javascript - Converting HTML list from json files -


i have problem code when listing countries json file:

my html

<div id="country">country</div> 

my js code

$.getjson( "country.js", function( data ) {   var items = [];   $.each( data, function( key, val ) {     items.push( "<li id='" + key + "'>" + val + "</li>" );   });    $( "<ul/>", {     html: items.join( "" )   }).appendto( "#country" ); }); 

fiddle link

your json source wrong.

  1. remove var countrylist =
  2. find code: 'tf' , change "code": "tf"
  3. you accessed wrong variable.

    items.push( "<li id='" + val.countrycode + "'>" + val.countrname + "</li>" );


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -