我不确定我做错了什么。我将它放在尸体中,旁边是div myDiv
,似乎没有跑,所以我不知道我做错了什么。
<script type="text/javascript" language="javascript">
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://www.example.com/test.php",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
</script>
<div id="myDiv"></div>
答案 0 :(得分:2)
脚本在渲染div“myDiv”之前运行。交换它们......
<div id="myDiv"></div>
<script type="text/javascript" language="javascript">
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://www.example.com/test.php",false);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;