Checking if the download link works without downloading the file

Is there a way in Javascript (and jQuery) to check if a URL is a 200 status (specifically not 404) without loading its content if it is actually a 200 status?

For example, I want to check if the download link on a video is working before executing any code. The problem when I use $.ajax()

is that when the link actually works, it will only notify me AFTER the download is complete. Is there some way to just "ping" the URL to see if it works without its contents?

+3


source to share


1 answer


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 mostly used by browsers to validate the cache, but it should work here as well.

+7


source







All Articles