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.
- remove
var countrylist = - find
code: 'tf', change"code": "tf" you accessed wrong variable.
items.push( "<li id='" + val.countrycode + "'>" + val.countrname + "</li>" );
Comments
Post a Comment