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?
You can try a HEAD request, which should accomplish what you are trying to do:
jQuery.ajax({type: "HEAD", url: "http://google.com/"})
This type of request is mainly used by browsers to check cache validity, but it also should work here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With