您的位置:首页 > Web前端 > JavaScript

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

2011-12-01 16:12 281 查看
function getTextResponse(theurl)

{

//var ajax = InitAjax();

ajax.open("GET", theurl, false);

ajax.send(null);

if (ajax.readyState == 4 && ajax.status == 200) {

  var value =ajax.responseText;

}

else

{

value = -1;

}

return value;

}

function InitAjax()

{

 var ajax=false;

 try {

  ajax = new ActiveXObject("Msxml2.XMLHTTP");

 } catch (e) {

  try {

   ajax = new ActiveXObject("Microsoft.XMLHTTP");

  } catch (E) {

   ajax = false;

  }

 }

 if (!ajax && typeof XMLHttpRequest!='undefined') {

  ajax = new XMLHttpRequest();

 }

 return ajax;

}

var ajax = InitAjax();

var theurl="http://www.qq.com/index.htm";

var value = getTextResponse(theurl);

alert(value);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: