.html

  1. <script>
  2. http("top/playlist/?cat=华语").then(res=>{
  3. let id=res.playlists[0].id;
  4. return id;
  5. }).then(res=>{
  6. let id=res;
  7. http(`playlist/detail?id=${id}`).then(res=>{
  8. var {name,id}=res.playlist.tracks[0]
  9. console.log(id);
  10. })
  11. })
  12. </script>

index.js

  1. function http(url){
  2. return new Promise((resolve,reject)=>{
  3. $.ajax({
  4. url:`http://192.168.4.18:3000/${url}`,
  5. type:"get",
  6. success:res=>{
  7. resolve(res)
  8. },
  9. error:err=>{
  10. reject(err)
  11. }
  12. })
  13. })
  14. }