<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                1. 創建一個Promise實例 ``` var url = 'https://douban.uieee.com/v2/movie/top250'; /* new 一個Promise對象 */ var promise = new Promise((resolve, reject)=>{ /* 發送一個異步請求,執行$.ajax方法 */ $.ajax({ url, dataType: 'jsonp', success(res){ /* 請求成功則執行resolve方法 */ resolve(res); }, error(err){ /* 請求失敗則執行reject方法 */ reject(err); } }) }) /* promise對象 */ promise.then(res=>{ /* .then()內是resolve方法 , 等待promise中的異步行為結束后才執行*/ console.log(res); // .then內可寫成: /* function(res){ console.log(res) } */ },err=>{ /* 否則則執行`,err`內的方法 */ console.log(err.status); }) ``` 2. 封裝一個Promise實例,實現promise鏈式then ``` 使用promise封裝ajax請求 function promise(url){ return new Promise((resolve, reject)=>{ $.ajax({ url, dataType: 'jsonp', success(res){ resolve(res) }, error(err){ reject(err); } }); }); } ``` 使用promise ``` var url = 'https://douban.uieee.com/v2/movie/top250'; promise(url).then(res=>{ /* promise請求top250 */ var id = res.subjects[0].id; let url = 'https://douban.uieee.com/v2/movie/' + id; // console.log(id); /* 獲得top250的第一項的url */ return promise(url); /* 使用promise處理url, 將這個方法return出去 */ }).then(res=>{ /* 在這里會打印第一個電影 */ console.log(res); }) ``` 這種方法可以避免回調地獄
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看