简体   繁体   中英

XMLHttpRequest failing on new server

I have the following Javascript function working perfectly on my localhost IIS server. When I migrate the code to my other IIS server (it's a Windows VPS), the xmlhttp.status is always returning as 404 (even though the file that it's checking for is there).

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);
}

I suspect that the XMLHttpRequest is failing on the new server. The fname variable has the right path/filename. The function handleHttpResponse_check function is executing correctly...just that xmlhttp.status is always returning 404 on the new server despite the file being at the path/filename. The localhost server detects the file perfectly and xmlhttp.status returns 200 on that server. Any ideas what might be going on with the new server?

A 404 status code means that the server has not found anything matching the Request-URI. Check the path to the requested resource to ensure that the generated path is the intended path and see if you can access that resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM