我想用ajax做一些非常簡單的事情。我有一個文件夾在我的Mac與2文件:index.html和text.txt。ajax問題顯示簡單文檔的內容
的index.html:
<p>
<input type="button" onclick="loadDoc()" value="CLICK" />
</p>
<p id="fileContent"></p>
<script>
function loadDoc() {
var xhr = new XMLHttpRequest();
xhr.open('GET', "text.txt", true);
xhr.onreadystatechange = function() {
document.getElementById('fileContent').innerHTML = xhr.responseText;
}
xhr.send(null);
}
</script>
的text.txt:
hello
當用戶點擊CLICK按鈕時,我想讓按鈕CLICK下方出現text.txt'hello'的內容。
它不適用於我的Mac本地。你知道爲什麼嗎?
謝謝!