0
我在下面的代碼中遇到問題。它在firefox v50.X上運行完美,但不適用於Chrome v55.X.JS - AJAX適用於Firefox但不適用於Chromerome
HTML
<!doctype html>
<html>
<head>
<script>
function load(){
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("container").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "name.html", true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="submit" onclick="load();">
<div id="container"></div>
</body>
</html>
name.html
<html>
<body>
<p>Test.</p>
</body>
</html>
爲什麼不工作鉻此代碼?
請提供來自谷歌Chrome的Developper控制檯的錯誤。你可以在'參數 - >更多工具 - >開發工具'中找到它。它會打開一個新窗口,您應該從中看到選項卡控制檯。 –
我不完全確定,但是您是否嘗試過使用name.html中的''和'
'標記?如果您要動態加載內容,它們不應該在那裏。 –