第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

fetch第一層回調(diào)的結(jié)果response是什么,為什么返回的數(shù)據(jù)是在第二層then里面

fetch第一層回調(diào)的結(jié)果response是什么,為什么返回的數(shù)據(jù)是在第二層then里面

達(dá)令說 2019-03-20 22:15:16
比如fetch(url).then(function(response) {  return response.json();}).then(function(data) {  console.log(data);}).catch(function(e) {  console.log("Oops, error");});一般我們想要的數(shù)據(jù)在第二層then里面,那第一層then的respose有什么用,為什么還要return?里面是什么信息?狀態(tài)碼?
查看完整描述

2 回答

?
溫溫醬

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊

response是Response對象,包含Header、status、statusText等屬性。要獲得具體數(shù)據(jù)需要使用.json(用于JSON)、.text(用于文本)、.formData(用于FormData對象)等方法。
至于為什么需要return,因?yàn)?code>Response.json返回的是一個(gè)Promise,所以只能先return,再在下一層處理。

fetch(url).

    then(function(response) {

        // 打印響應(yīng)頭

        console.log(response.headers);

        //打印狀態(tài)碼

        console.log(response.status);

        //打印狀態(tài)信息

        console.log(response.statusText);

        // 使用.json方法獲得具體返回?cái)?shù)據(jù),再下一層Promise里處理

        return response.json();

    })

    .then(function(data) { console.log(data); })

    .catch(function(e) { console.log("Oops, eror");


查看完整回答
反對 回復(fù) 2019-04-08
  • 2 回答
  • 0 關(guān)注
  • 871 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號