How does jquery determine whether a file exists

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



The operating environment of this tutorial: windows7 system, jquery 3.2.1 version, this method is applicable to all brand computers.

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

determine whether a file exists with

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

usage var Exists=Exists('/cache/view_num/'+uid+ '.txt');if(Exists){}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

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;

}

}

Guess you like

Origin blog.csdn.net/ld17822307870/article/details/113831534