如果你不想使用jQuery這是 $一樣簡單( 「結果」)。負載( 「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>
您需要該頁面來自同一個來源。可以?即是在本地主機,同一端口,相同的協議上承載腳本的頁面?無論如何,如果你沒有計劃顯示iframe,你爲什麼將它附加到身體? – mplungjan
因爲我需要觸發下載而不刷新頁面 – Roberval
這並沒有讓我更聰明 - 爲什麼追加它。任何爲什麼不使用AJAX – mplungjan