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.
1 Answer
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');
},
})
6 Comments
dezman
will this work with relative paths, lets say i just have url: 'abc.html'?
Diodeus - James MacFarlane
That answer was given on one of the referenced questions. Why is this different?
dezman
and what about a fail alert?
karthikr
Refer to this: stackoverflow.com/questions/3646914/… This answer is essentially the same
Alex Wayne
@watson api.jquery.com/jQuery.ajax
|
mydomain.com/mypage.htmlchecking on a file somewhere likesomewhereelse.com/somefile.txt? Or ismydomain.com/mypage.htmlcheck on a file somewhere likemydomain.com/somefile.txt?