模拟下载的问题即

时间:2011-07-14 11:41:10

标签: javascript

我在做:

iframe = document.createElement("iframe");
frame.src="http://localhost/file.csv";
iframe.style.display='none';
document.body.appendChild(iframe);

它在ff,chrome,safari上工作得很好,但是总是会传出阻止它的安全信息。

有人知道如何解决它吗?

1 个答案:

答案 0 :(得分:0)

如果你不想使用简单的jQuery $(“result”)。load(“file.csv”),然后看看这里

http://plungjan.name/test/simpleajax.html

<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>