【发布时间】:2017-01-09 08:28:38
【问题描述】:
我有一个简单的方法来检查我的本地机器中的*.mp3 文件是否存在。
它应该返回响应的status(200、404,403等),但它不起作用。
fileExists(url){
return this.http.get(url).timeout(2000)
.map(res=>res.json())
.subscribe(
res=>{
console.log("res is");
console.log(res.status)
return res.status;},
err =>{
console.log("Error is");
console.log(err.status);
return err.status});
}
我为它设置了 2 秒的超时时间,但它只需要检查我的本地主机中的文件。因此,我认为,它有足够的时间找到文件。
它总是返回:
Subscriber {closed: false, syncErrorValue: null, syncErrorThrown: false, syncErrorThrowable: false, isStopped: false…}
【问题讨论】:
-
返回的状态是你在后台定义的。没有?
-
不是,是http请求的状态。
-
@Salman,你使用什么后端框架?如果您使用的是 apache 之类的后端,那么您将把它留给 apache 来为您提供状态,如果您使用的是 nodejs/django 之类的后端,您可能需要定义如何获取文件?
标签: angular