【发布时间】:2018-10-28 07:24:57
【问题描述】:
我正在用 JavaScript 编写一个小程序。基本上,我想使用 Promise 和 fetch 从两个文本文件中提取文本。但是,我不知道如何从文件中获取实际文本。这是我当前的代码。
示例.txt
this is
a sample
text file.
sample2.txt
this is
the second
sample file.
index.js
function getSampleText() {
Promise.all([
fetch('sample.txt'),
fetch('sample2.txt')
]).then(allResp => {
let sampleResp = allResp[0];
let sample2Resp = allResp[1];
console.log(sampleResp);
console.log(sample2Resp);
})
}
这是 Promises...我如何从中获取文本?
【问题讨论】:
标签: javascript asynchronous promise fetch-api