【发布时间】:2017-10-17 19:30:07
【问题描述】:
如何从 Fetch URL 下载所需的 JSON?
在 XLSX 中下载。
代码
function teste (){
alert(fetch ("url")
.then(response => response.json())
.then(data => { console.log(data)})
.then(response => response.blob())
.then(blob => {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = "filename.xlsx";
a.click();
})
)
}
【问题讨论】:
-
alert()的目的是什么?第二个.then()没有返回值 -
好吧,一方面,第一个
.then()没有传播data,这意味着第二个.then()的response是undefined。 -
为了做一个测试,我不知道它是否正确它是形式。
标签: javascript json fetch