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.
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!