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

How to determine if a file exists with jquery

coldplay.xixi
Release: 2023-01-04 09:37:02
Original
2373 people have browsed it

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;
}
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template