使用javascript测试文件是否存在 [英] Test if a file exists with javascript
本文介绍了使用javascript测试文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题已经被问到这里和此处。但是我尝试了三个没有好运的答案。我正在使用一个名为Niagara的系统,它充当了Web服务器,这可能是这些技术不起作用的原因。尽管如此,我觉得必须有办法检查文件是否存在,而不是存在404或200或0.
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.
推荐答案
您可以使用 $。ajax
$.ajax({
url: 'example.com/abc.html', //or your url
success: function(data){
alert('exists');
},
error: function(data){
alert('does not exist');
},
})
这篇关于使用javascript测试文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文