提取数据并将数据转换为CSV并下载

时间:2020-07-03 15:45:47

标签: javascript csv download fetch

我有一个获取的端点,该端点返回CSV。我试图在单击时将该字符串导出为CSV文件。响应中的标头包含content-dispostion,其内容类型为'text / csv'。

我该怎么做?

let download = await function(){
  let response = await fetch('www.endpointblahblah.com')
  
  //The rest of the function needs to take the string that's returned from the response and export as a CSV file by downloading it.
}

将响应转换为JSON会引发错误。绝对应该这样做,因为不返回JSON对象,而是文本。

谢谢。

0 个答案:

没有答案