0
我試圖做一個獲取API調用來與我的陣營,原生應用一個新的火力地堡的實例,但我遇到了這個錯誤:可能未處理的承諾拒絕 - 陣營本土與火力地堡
Possible Unhandled Promise Rejection (id: 0):
Network request failed
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25119:8)
at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:10405:15)
at XMLHttpRequest.setReadyState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:26688:6)
at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:26536:6)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:26630:52
at RCTDeviceEventEmitter.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:9638:23)
at MessageQueue.__callFunction (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7493:34)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7375:8
at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7306:1)
at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7374:1)
的功能看起來像這樣:
getNotes(username){
username = username.toLowerCase().trim();
var url = `https://myproject-6342.firebaseio.com/${username}.json`;
return fetch(url).then((res) => res.json());
},
addNote(username, note){
username = username.toLowerCase().trim();
var url = `https://myproject-6342.firebaseio.com/${username}.json`;
return fetch(url, {
method: 'post',
body: JSON.stringify(note)
}).then((res) => res.json());
}
這是怎麼回事?