日期:2014-05-16  浏览次数:20329 次

js判断服务器文件是否存在

var? urlImages=window.location.protocol + "//" + window.location.host +? "<c:url value="/printTempImages/common/" />";

?

?//判断图片是否存在
?function checkimg(obj){
??//alert(obj);
??var s;
??var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
??xmlhttp.open("GET",obj,false);?
??xmlhttp.send();
??if(xmlhttp.readyState==4)
??{
???if(xmlhttp.status==200)
????s=true; //url存在
???else if(xmlhttp.status==404)
????s=false; //url不存在
???else
????s=false;//其他状态
??}
?? //alert(s);?
?? return s;
?}