Javascript XMLHttpRequest在新服务器上失败

Javascript XMLHttpRequest在新服务器上失败,javascript,iis,xmlhttprequest,onreadystatechange,Javascript,Iis,Xmlhttprequest,Onreadystatechange,我在本地主机IIS服务器上使用了以下Javascript函数。当我将代码迁移到另一台IIS服务器(它是Windows VPS)时,xmlhttp.status总是返回404(即使它正在检查的文件在那里) 函数startInterval(结果){ //变量fname=”http://localhost/excelfiles/Ad_Activity_1_145.csv"; 变量路径=”http:///excelfiles/"; var fname=path+a.substring(0,a.leng

我在本地主机IIS服务器上使用了以下Javascript函数。当我将代码迁移到另一台IIS服务器(它是Windows VPS)时,xmlhttp.status总是返回404(即使它正在检查的文件在那里)

函数startInterval(结果){
//变量fname=”http://localhost/excelfiles/Ad_Activity_1_145.csv";
变量路径=”http:///excelfiles/"; 
var fname=path+a.substring(0,a.length-1)+“活动”+c++“结果”+.csv”;
var校验计数器=0;
checkInterval=setInterval(函数(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open('HEAD',fname);
xmlhttp.onreadystatechange=handleHttpResponse_check;
xmlhttp.send(空);
函数handleHttpResponse_check()
{
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
//ctrl.innerHTML='打开文件!';
ctrl.innerHTML='';
clearInterval(检查间隔);
}else if(xmlhttp.status==404){
校验计数器+=1;
如果(校验计数器>=5){
clearInterval(检查间隔);
ctrl.innerHTML='错误:未创建文件';
}                                                                                                                 
}
}
}
}, 1000);
}

我怀疑XMLHttpRequest在新服务器上失败。fname变量具有正确的路径/文件名。函数handleHttpResponse_check正在正确执行…只是新服务器上的xmlhttp.status总是返回404,尽管文件位于路径/文件名处。localhost服务器完美地检测到该文件,xmlhttp.status在该服务器上返回200。你知道新服务器可能发生了什么吗?

404状态码表示服务器没有找到任何与请求URI匹配的内容。检查所请求资源的路径,以确保生成的路径是预期路径,并查看您是否可以访问该资源。

它试图访问的完整路径是什么?Doggone it…。就是这样,路径指向错误的文件夹。如果您找到答案,把它写在下面并接受它。@AdamChubbuck-如果你把你的答案作为解决方案发布,我会接受它。@swabygw谢谢你。
function startInterval(result) {
  //var fname = "http://localhost/excelfiles/Ad_Activity_1_145.csv";
  var path = "http://<% =Request.Url.Host %>/excelfiles/"; 
  var fname = path + a.substring(0,a.length-1) + "_Activity_" + c + '_' + result + '.csv';
  var checkCounter = 0;
  checkInterval = setInterval(function() {
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open('HEAD', fname);
  xmlhttp.onreadystatechange = handleHttpResponse_check;
  xmlhttp.send(null);

  function handleHttpResponse_check()
  {
    if(xmlhttp.readyState == 4){
      if (xmlhttp.status == 200) {
        //ctrl.innerHTML = '<a onclick="goToURL(\''+fname+'\');return false;">Open file!</a>';
        ctrl.innerHTML = '<a onclick="goToURL(\''+fname+'\');return false;"><img src="images\\Excel_Icon.jpg" style="width:20px;height:20px;cursor:pointer;"/></a>';
        clearInterval(checkInterval);
        } else if (xmlhttp.status == 404) {
          checkCounter += 1;
          if(checkCounter >= 5){
          clearInterval(checkInterval);
          ctrl.innerHTML = 'ERROR: File not created';
          }                                                                                                                 
        }
      }
    }

  }, 1000);
}