gpt4 book ai didi

javascript - 从 Express 后端下载 .csv 到 Angularjs

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:14 24 4
gpt4 key购买 nike

我也看到过同样的问题 here ,但是该解决方案在我的情况下不起作用,并输入所使用的代码片段

$('<form action="'+ url +'" method="'+ ('post') +'">'+inputs+'</form>')
.appendTo('body').submit().remove();

返回Reference $未定义的错误

我有一个如下所示的下载请求:

Controller .js

$http.put('/download' {file:$scope.inputInfo.name.$modelValue+'.csv'}).success(function(data,status,headers){
console.log(status);
console.log(data);

})

app.js

app.put('/download', function(req,res){
console.log(req.body.file)
res.download(__dirname +'/'+ 'req.body.file, function(err){
if(err){console.log(err)}
})

})

我的controller.js 将原始文件输出作为数据返回,而不是从页面启动下载。我是否缺少某些东西来以 Angular 启动此文件下载?任何帮助将不胜感激。

最佳答案

Seth由于我的页面上缺少 jQuery,您完全为我指明了正确的方向。

这是我添加到controllers.js 中代替 $http.put() 的完成代码:

$('<form action="'+ "/download" +'" method="'+ ('post') +'">'+'<input type="hidden" name="file" value="'+$scope.inputInfo.name.$modelValue+'"'+'/></form>')
.appendTo('body').submit().remove();

再次感谢您对此的帮助。

关于javascript - 从 Express 后端下载 .csv 到 Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25314440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com