Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!doctype html> <title>Example</title> <!-- Load JQuery --> <script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <!-- Load JSON file and output it--> <script> $(function() { // User clicks the "getData" button $("#getData").click(function() { // Put artistList element and JSON file location into a variable var artistList = $("#artistList"); var url = "/json/tutorial/artists.txt"; // Get the JSON file $.getJSON(url, function(data) { // Put artist info into a variable var artists = data.artists.map(function(item) { return item.artistname + " (" + item.born + ")"; }); // Remove all child nodes (including text nodes) artistList.empty(); // Format artists with HTML tags if (artists.length) { var content = "<li>" + artists.join("</li><li>") + "</li>"; var list = $("<ul>").html(content); artistList.append(list); } }); }); }); </script> <!-- The output appears here --> <button id="getData">Display Artists</button> <div id="artistList"></div>