-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.html
49 lines (42 loc) · 1.38 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="icon" href="data:;base64,=">
</head>
<body>
<div class="container">
<h1>Testing the Spotify API</h1>
<button type="button" id="go">Click</button>
<div id="results"></div>
<iframe id="music" src="https://embed.spotify.com/?uri=spotify%3Aalbum%3A2rp5riHULWgrXPsDtsp1ir" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>
</div>
<script>
var artist_data = "",
artist_id = "",
artist_name = "Heifetz"
document.getElementById("go").addEventListener("click", function() {
$.ajax({url:'http://ws.spotify.com/search/1/artist.json?q=' + artist_name,
success: function(data) {
artist_data = data["artists"][0]["href"];
artist_list = artist_data.split(":");
artist_id = artist_list[2];
setAlbum(artist_id);
}
});
});
var setAlbum = function(artist_id) {
$.ajax({
url: 'https://api.spotify.com/v1/artists/'+artist_id+'/albums',
success: function(data) {
album_uri = data["items"][0]["uri"];
music_src = "https://embed.spotify.com/?uri=" + album_uri;
document.getElementById("music").setAttribute("src",music_src);
}
})
}
</script>
</body>
</html>