回调地狱:由多层嵌套的回调函数组成的代码
    QQ截图20201208205919.png

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>Document</title>
    7. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    8. <style>
    9. body{
    10. background-color: pink;
    11. }
    12. </style>
    13. </head>
    14. <body>
    15. <div id="app"></div>
    16. <h2>列表数据</h2>
    17. <p class="dp"></p>
    18. <audio src="" controls></audio>
    19. <script>
    20. var url ='http://192.168.4.18:3000/top/playlist/?cat=华语';
    21. $.ajax({
    22. url,
    23. success:res=>{
    24. var {name,id} = res.playlists[0]
    25. $("#app").html(name)
    26. /* 2.列表页的数据 */
    27. var listUrl = `http://192.168.4.18:3000/playlist/detail?id=${id}`;
    28. $.ajax({
    29. url:listUrl,
    30. success:res=>{
    31. var {name,id} = res.playlist.tracks[0]
    32. $(".dp").html(name)
    33. console.log(id)
    34. /* 3.根据id获取音乐播放的url链接 */
    35. var musicUrl = `http://192.168.4.18:3000/song/url?id=${id}`
    36. $.ajax({
    37. url:musicUrl,
    38. success:res=>{
    39. let src = res.data[0].url;
    40. $("audio").attr("src",src)
    41. }
    42. })
    43. }
    44. })
    45. }
    46. })
    47. </script>
    48. </script>
    49. </body>
    50. </html>