Implementing the initialize method

In this method, we will load the JSON from the server and display the album names in the left panel. Write the following code inside the initialize method to get the JSON from the server:

$.getJSON( "albums.json", function(data) 
{
  albums.jsonAlbums = data;
  albums.fillAlbumNames();
  albums.addEventHandlers();
});

Here we are using jQuery's getJSON method to fetch JSON from the server. We have specified albums.json as the URL and a success handler when a response is received. In success event handler, response is received in a variable data that we place in property jsonAlbums.

Next, we call the methods fillAlbumNames and addEventHandlers of the albums object.

Get Mastering jQuery UI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.