javascript - 从浏览器下载 csv 文件:不工作
问题描述
我正在尝试从浏览器下载 CSV 文件,但它什么也没做。教授给出了这段代码,它在他的例子中有效,但在我的例子中不起作用。
if ( !err ) {
console.log("Working with: ",row.sheet);
// convert to javascript object
let values = JSON.parse( row.sheet );
console.log("VALUES CONTAINS: ",values);
let csv = ''
for( let row of values ) {
csv += CSV.stringify( row );
}
console.log('sending csv ',csv);
res.set('Content-Type', 'text/plain')
// tell the browsers to download to a file
res.set('Content-Disposition',
`attachment; filename="${name}.csv"`);
console.log('check status csv: ',csv);
res.send( csv );
}
console.logs 都在工作,只是没有弹出下载