jQuery 使用javascript测试文件是否存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16553174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Test if a file exists with javascript
提问by dezman
This question has already been asked hereand 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.
这个问题已经在这里和这里被问到了。但是我已经尝试了三个答案,但运气不佳。我正在使用一个名为 Niagara 的系统,它充当 Web 服务器,这可能是这些技术不起作用的原因。尽管如此,我觉得必须有一种方法来检查文件是否存在,而不是 404 或 200 或 0 的存在。
回答by karthikr
You can use $.ajax
您可以使用 $.ajax
$.ajax({
url: 'example.com/abc.html', //or your url
success: function(data){
alert('exists');
},
error: function(data){
alert('does not exist');
},
})