Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if a file exists with javascript [duplicate]

This question has already been asked here and here. But I have tried three of the answers with no good luck. I am using a system called Niagara which is acting as a web server, which may be the reason these techniques did not work. Nonetheless, I feel there must be a way to check for the existence of a file, not the existence of a 404 or 200 or 0.

like image 571
dezman Avatar asked Aug 23 '26 11:08

dezman


1 Answers

You can use $.ajax

$.ajax({
  url: 'example.com/abc.html', //or your url
  success: function(data){
    alert('exists');
  },
  error: function(data){
    alert('does not exist');
  },
})
like image 84
karthikr Avatar answered Aug 25 '26 00:08

karthikr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!