回调地狱:由多层嵌套的回调函数组成的代码
<div id="app"></div>
<h2>列表数据</h2>
<p class="dp"></p>
<audio src="" controls></audio>
<script>
/* 1.华语中的第一条数据 */
var url = 'http://192.168.4.18:3000/top/playlist/?cat=华语'
$.ajax({
url,
success:res=>{
var {name,id} = res.playlists[0]
$("#app").html(name)
/* 2.列表页数据 */
var listUrl = `http://192.168.4.18:3000/playlist/detail?id=${id}`
$.ajax({
url:listUrl,
success:res=>{
var {name,id} = res.playlist.tracks[0]
$(".dp").html(name)
/* 3.根据id获取音乐播放器的url连接 */
var musicUrl = `http://192.168.4.18:3000/song/url?id=${id}`
$.ajax({
url:musicUrl,
success:res=>{
let src = res.data[0].url
$("audio").attr("src",src)
}
})
}
})
}
})
</script>