封装

    1. function http() {
    2. return new Promise((resolve, reject) => {
    3. $.ajax({
    4. url,
    5. success: res => {
    6. resolve(res)
    7. },
    8. error: err => {
    9. reject(err)
    10. }
    11. })
    12. })
    13. }
    1. <script>
    2. var url = 'http://47.108.197.28:3000/top/playlist?order=hot'
    3. http(url).then(res=>{
    4. var id = res.playlists[0].id
    5. return id
    6. }).then(id=>{
    7. var url = `http://47.108.197.28:3000/top/playlist/detail?id=${id}`
    8. http(url).then(res=>{
    9. console.log(res);
    10. })
    11. })
    12. </script>