Home  >  Article  >  Web Front-end  >  How to determine if a file exists with jquery

How to determine if a file exists with jquery

coldplay.xixi
coldplay.xixiOriginal
2020-12-11 14:27:192325browse

The jquery method to determine whether a file exists: first encapsulate a fileExists method and receive url parameters; then use the [$.ajax()] method to send a request and set a synchronous request; and finally return the request result.

How to determine if a file exists with jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, thinkpad t480 computer.

Related free learning recommendations: javascript (video), jQuery tutorial (video )

Jquery method to determine whether a file exists:

js or jquery determines whether a file exists, you need to use ajax

Usagevar Exists=Exists('/cache/view_num/' uid '.txt');if(Exists){}

 function fileExists(url){
var isExists;
$.ajax({
url:url,
async:false,
type:'HEAD',
error:function(){
isExists=0;
},
success:function(){
isExists=1;
}
});
if(isExists==1){
return true;
}else{
return false;
}
}

For more programming related knowledge, please visit:Programming Teaching! !

The above is the detailed content of How to determine if a file exists with jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn