javascript - 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.
推荐阅读
- java - 在 Spring MVC 中,API 相关的逻辑应该放在哪里?
- android - 在 TextInputLayout 内编辑未命名的 EditText 会引发 FrameLayout cannot be cast to EditText 错误
- git - Azure DevOps 构建管道无法使用标记和路径筛选器构建
- python - 从 NumPy 数组中删除时间戳
- node.js - 分叉电子过程需要“空”电子
- java - 使用 spring 数据存储库而不是生成的轴突存储库
- firebase - ChangeNotifier 过早地处理模型
- datagrid - 每次在表单 IO 数据网格中触发行数据的单击事件时,如何发送唯一的行索引?
- qt - 在Qt中使用返回双数组的java方法
- python - 将行列表转换为 PySpark 数据框