次の Javascript 関数が、localhost IIS サーバーで完全に機能しています。コードを他の IIS サーバー (Windows VPS) に移行すると、xmlhttp.status は常に 404 を返します (チェック対象のファイルがそこにある場合でも)。
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);
}
新しいサーバーで XMLHttpRequest が失敗していると思われます。fname 変数には正しいパス/ファイル名があります。関数 handleHttpResponse_check 関数は正しく実行されています...ファイルがパス/ファイル名にあるにもかかわらず、新しいサーバーで xmlhttp.status が常に 404 を返しているだけです。localhost サーバーはファイルを完全に検出し、xmlhttp.status はそのサーバーで 200 を返します。新しいサーバーで何が起こっているのでしょうか?