Suppose you need to create a single HTML page to display data, but the data comes from another website source. This HTML example will show you how to access the data using jQuery then present it on your single-page web app.
In this example, I still display the names of famous classical composers on my SPA by dynamically loading JSON from a different website.
Our model will consist of a JSON file that contains a single key "author".
[
{ "author": "Wolfgang Amadeus Mozart" },
{ "author": "Johann Sebastian Bach" },
{ "author": "Ludwig van Beethoven" },
{ "author": "Johannes Brahms" },
{ "author": "Antonín Dvořák" },
{ "author": "Isaac Albéniz" },
{ "author": "Tomaso Albinoni" },
{ "author": "Alessandro Scarlatti" },
{ "author": "Samuel Barber" },
{ "author": "Agustín Barrios" },
{ "author": "Béla Bartók" },
{ "author": "Hector Berlioz" },
{ "author": "Georges Bizet" },
{ "author": "Alexander Borodin" },
{ "author": "Max Bruch" },
{ "author": "Anton Bruckner" },
{ "author": "Ferruccio Busoni" },
{ "author": "Frédéric Chopin" },
{ "author": "Aaron Copland" },
{ "author": "Arcangelo Corelli" },
{ "author": "Claude Debussy" },
{ "author": "Domenico Scarlatti" },
{ "author": "Paul Dukas" },
{ "author": "Gabriel Fauré" },
{ "author": "John Field" },
{ "author": "George Gershwin" },
{ "author": "Philip Glass" },
{ "author": "Enrique Granados" },
{ "author": "Edvard Grieg" },
{ "author": "George Frideric Handel" },
{ "author": "Joseph Haydn" },
{ "author": "Leoš Janáček" },
{ "author": "Johann Christian Bach" },
{ "author": "Aram Khachaturian" },
{ "author": "Zoltán Kodály" },
{ "author": "Erich Wolfgang Korngold" },
{ "author": "Morten Lauridsen" },
{ "author": "Franz Liszt" },
{ "author": "Gustav Mahler" },
{ "author": "Felix Mendelssohn" },
{ "author": "Niccolò Paganini" },
{ "author": "Arvo Pärt" },
{ "author": "Francis Poulenc" },
{ "author": "Sergei Prokofiev" },
{ "author": "Giacomo Puccini" },
{ "author": "Henry Purcell" },
{ "author": "Sergei Rachmaninoff" },
{ "author": "Maurice Ravel" },
{ "author": "Erik Satie" },
{ "author": "Franz Schubert" },
{ "author": "Robert Schumann" },
{ "author": "Alexander Scriabin" },
{ "author": "Jean Sibelius" },
{ "author": "Johann Strauss II" },
{ "author": "Igor Stravinsky" },
{ "author": "Pyotr Ilyich Tchaikovsky" },
{ "author": "Antonio Vivaldi" },
{ "author": "Richard Wagner" },
{ "author": "Eric Whitacre" },
{ "author": "John Williams" },
{ "author": "Nikolai Rimsky-Korsakov" },
{ "author": "Gioachino Rossini" },
{ "author": "Camille Saint-Saëns" },
{ "author": "Dmitri Shostakovich" },
{ "author": "Bedřich Smetana" },
{ "author": "Georg Philipp Telemann" },
{ "author": "Ralph Vaughan Williams" },
{ "author": "Giuseppe Verdi" },
{ "author": "Franz von Suppé" },
{ "author": "Edward Elgar" },
{ "author": "Carl Philipp Emanuel Bach" },
{ "author": "Giovanni Pierluigi da Palestrina" },
{ "author": "Claudio Monteverdi" },
{ "author": "Modest Mussorgsky" },
{ "author": "Josquin des Prez" },
{ "author": "Jean-Baptiste Lully" },
{ "author": "Jean-Philippe Rameau" },
{ "author": "Charles Ives" },
{ "author": "Paul Hindemith" },
{ "author": "Olivier Messiaen" },
{ "author": "William Byrd" },
{ "author": "Hildegard of Bingen" },
{ "author": "François Couperin" },
{ "author": "Benjamin Britten" },
{ "author": "César Franck" },
{ "author": "Gustav Holst" },
{ "author": "Anton Webern" },
{ "author": "Dieterich Buxtehude" },
{ "author": "Gaetano Donizetti" },
{ "author": "Thomas Tallis" },
{ "author": "Ottorino Respighi" },
{ "author": "Guillaume de Machaut" },
{ "author": "Mikhail Glinka" },
{ "author": "Alban Berg" },
{ "author": "Steve Reich" },
{ "author": "Vincenzo Bellini" },
{ "author": "Arnold Schoenberg" },
{ "author": "Muzio Clementi" },
{ "author": "John Dowland" },
{ "author": "John Cage" },
{ "author": "Pérotin" },
{ "author": "Heitor Villa-Lobos" },
{ "author": "Carlo Gesualdo" },
{ "author": "Michael Praetorius" },
{ "author": "Johann Jakob Froberger" },
{ "author": "Barbara Strozzi" },
{ "author": "Johann Pachelbel" },
{ "author": "Wilhelm Friedemann Bach" },
{ "author": "Carl Ditters von Dittersdorf" },
{ "author": "Antonio Salieri" },
{ "author": "Johann Nepomuk Hummel" },
{ "author": "Carl Czerny" },
{ "author": "Fanny Mendelssohn" },
{ "author": "Luigi Cherubini" },
{ "author": "Giacomo Meyerbeer" },
{ "author": "Johann Strauss I" },
{ "author": "Fernando Sor" },
{ "author": "Mauro Giuliani" },
{ "author": "Louis Spohr" },
{ "author": "Carl Maria von Weber" },
{ "author": "Luigi Cherubini" },
{ "author": "Luigi Boccherini" },
{ "author": "Johann Stamitz" },
{ "author": "Carl Stamitz" },
{ "author": "Leopold Mozart" },
{ "author": "Michael Haydn" },
{ "author": "Antonio Caldara" },
{ "author": "Johann Adolph Hasse" },
{ "author": "Girolamo Frescobaldi" },
{ "author": "Heinrich Schütz" },
{ "author": "Francesco Cavalli" },
{ "author": "Thomas Campion" },
{ "author": "Philippe de Vitry" },
{ "author": "John Dunstaple" },
{ "author": "Giovanni Gabrieli" },
{ "author": "Domenico Gabrielli" },
{ "author": "Charles Gounod" },
{ "author": "Jules Massenet" },
{ "author": "Guillaume Dufay" },
{ "author": "Christoph Willibald Gluck"}
]
https://codepen.io/chrisaiv/pen/NNWvBO.js This HTML file dynamically loads jQuery, Pure.css, and the Model from CodePen (see above). Once the JSON loads, I run a loop that populates the text data into an HTML table.
This is the actual HTML working live.