我目前在页面上
Leader/Index.html
我想访问并从此处下载文件:
Leader/Data.csv
我的javascript文件中有代码,用我认为正确的文件路径创建iframe并创建IFrame,但服务器响应错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:49635/Leader/Data.csv
我认为路径是正确的,并且不明白它为什么不下载。这是javascript代码:
var downloadFrame = document.createElement("IFRAME");
if (downloadFrame != null) {
downloadFrame.setAttribute("src", '../Data.csv');
downloadFrame.style.width = "0px";
downloadFrame.style.height = "0px";
document.body.appendChild(downloadFrame);
}
我尝试将路径从“../Data.csv”更改为“Data.csv”无效。
感谢您的帮助!
答案 0 :(得分:0)
这取决于放置JS文件的位置。如果它与Index.html和Data.csv在同一目录中,那么您应该使用
downloadFrame.setAttribute("src", "./Data.csv");
另外,在第二个方面,我不认为你可以将csv放在Iframe源中并希望它能够正常工作。 请看这条评论:https://stackoverflow.com/a/34801182/3967800