-1

I have a route on my server that is used to serve files for download. Because of the nature of the app I cannot have a link to any file. Instead the browser client requests the file to the server which in turn request the file from a node client which returns the data back to the server. At this point the server saves the file and notifies the caller browser of the file being ready for request. Im using angular in the front end and to request the file I was trying to use $http.get(), with that in chrome's dev tools I could see the request happening successfully but the file would not download. Typing the link address outside of angular would download the file. In turn I ended up using$window.location.assign(url) and that did work. Could anyone explain why assign() worked and not $http.get()? What are the differences?

Thanks

4

1 回答 1

0

您不能使用 AJAX 请求或更好的说法是 XHR 来下载文件...... Angular 在拨打电话时会使用此功能。

参考这个:为什么没有办法使用ajax请求下载文件?

所以最简单的就是坚持你现在正在做的事情或使用一些第三方实用程序。

于 2014-07-30T04:56:09.360 回答