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

Is there a way in Javascript (and jQuery) to check if a URL is status 200 (specifically not 404) withou

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744183232a4562081.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信