Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ie上模拟下载的问题_Javascript - Fatal编程技术网

Javascript 在ie上模拟下载的问题

Javascript 在ie上模拟下载的问题,javascript,Javascript,我正在做: iframe = document.createElement("iframe"); frame.src="http://localhost/file.csv"; iframe.style.display='none'; document.body.appendChild(iframe); 它在ff、chrome、safari上运行良好,但在ie上,总是会出现一条关于安全性的信息来阻止它 有人知道如何修复它吗?如果您不想使用像 $(“result”).load(“file.csv”

我正在做:

iframe = document.createElement("iframe");
frame.src="http://localhost/file.csv";
iframe.style.display='none';
document.body.appendChild(iframe);
它在ff、chrome、safari上运行良好,但在ie上,总是会出现一条关于安全性的信息来阻止它


有人知道如何修复它吗?

如果您不想使用像 $(“result”).load(“file.csv”),然后在此处查看


Ajax示例
函数xmlhttpget(URL){
var xmlHttpReq=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject(“Microsoft.XMLHTTP”);
xmlHttpReq.open('GET',URL,true);
xmlHttpReq.onreadystatechange=函数(){
if(xmlHttpReq.readyState==4){
显示(xmlHttpReq.responseText);
}
}
xmlHttpReq.send();
}
功能显示(str){
document.getElementById(“结果”).innerHTML=str;
}

您需要页面来自同一来源。是吗?也就是说,承载脚本的页面是否也在本地主机、相同端口、相同协议上?无论如何,如果您没有计划显示iframe,为什么要将其附加到正文中?因为我需要在不刷新页面的情况下触发下载,这不会让我变得更明智-为什么要附加它呢。为什么不使用ajax?我如何用ajax模拟下载?
<html>
<head>
<title>Ajax Example</title>
<script type="text/javascript">
function xmlhttpget(URL) {
  var xmlHttpReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
  xmlHttpReq.open('GET', URL, true);
  xmlHttpReq.onreadystatechange = function() {
    if (xmlHttpReq.readyState == 4) {
      show(xmlHttpReq.responseText);
    }
  }
  xmlHttpReq.send();
}
function show(str){
    document.getElementById("result").innerHTML = str;
}
</script>
</head>
<body>
<div id="result"></div>
<input type="button" onclick="xmlhttpget('file.csv')" value="Get">
</form>
</body>
</html>