最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Checking if a download link is working without downloading the file - Stack Overflow

programmeradmin6浏览0评论

Is there a way in Javascript (and jQuery) to check if a URL is status 200 (specifically not 404) without downloading it's contents if it is in fact status 200?

For example, I want to check if a download link to a video works before executing some code. The issue when I use $.ajax() is that when the link does in fact work, it will only notify me AFTER the download has finished. In a way is there a way to just "ping" the url to see if it works without getting it's contents?

Is there a way in Javascript (and jQuery) to check if a URL is status 200 (specifically not 404) without downloading it's contents if it is in fact status 200?

For example, I want to check if a download link to a video works before executing some code. The issue when I use $.ajax() is that when the link does in fact work, it will only notify me AFTER the download has finished. In a way is there a way to just "ping" the url to see if it works without getting it's contents?

Share Improve this question edited Sep 17, 2014 at 6:16 thriqon 2,48820 silver badges24 bronze badges asked Sep 17, 2014 at 5:35 Tony LiTony Li 1471 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can try a HEAD request, which should acplish what you are trying to do:

jQuery.ajax({type: "HEAD", url: "http://google./"})

This type of request is mainly used by browsers to check cache validity, but it also should work here.

发布评论

评论列表(0)

  1. 暂无评论