Javascript.在不下载内容的情况下检查URL的响应类型 [英] Javascript. Checking the type of response from a URL without downloading content

查看:86
本文介绍了Javascript.在不下载内容的情况下检查URL的响应类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,可以在服务器上运行报告.这些报告在服务器上存储了一定的时间.当我发送报告URL时,服务器要么将报告发送回(XLS格式),要么返回简单的找不到文件"文本(无错误) 下次用户登录时,我希望能够检查报告是否仍然存在或需要再次运行.我可以简单地使用JQuery.ajax在后台调用URL并检查得到的响应类型.但是,这意味着这些报告已全部下载,我有10个(如果不是100个)潜在报告. 有什么方法可以查询服务器,以便仅获得将要获得的响应类型,而无需下载内容(即XLS或二进制文件->报告可用;文本->报告丢失)? 请注意,我无法控制服务器的行为. 谢谢

I have a web application that can run reports on a server. The reports are stored on the server for a certain amount of time. When I send the report URL, the server either sends the report back (in XLS format) or it returns a simple "file not found" text (no error) Next time the user logs in, I want to be able to check if the report is still there or it needs to be run again. I could simply use JQuery.ajax to call the URL in the background and check the type of response I get. However, this means that the reports are downloaded fully and I have 10s if not 100s of potential reports. Is there any way that I can query the server so that I only get the type of response that I will get, without downloading the content (i.e. XLS, or binary-> the report is available; text -> the report is missing)? Note that I have no control over the behavior of the server. Thanks

推荐答案

关闭循环,感谢您的评论,这促使我提出了此解决方案.使用JQuery,这就是我想出的方法,它似乎可以工作:

Closing the loop, thanks for your comments that led me to this solution. Using JQuery this is what I have come up with, which seems to work:

req=$.ajax({
    type:'HEAD',
    url:'url',
success: function() {
            if(req.getAllResponseHeaders().indexOf("ms-excel.sheet")>=0{}//report is available            
            else{} //report is not available             
        }
});

这篇关于Javascript.在不下载内容的情况下检查URL的响应类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆