我已经在像COBOL strucutured编程和努力学习AJAX现在。新建AJAX,需要一些澄清
我看到这一段代码在W3Schools的,并有以下几个问题?
问题: 1. xmlhttp.onreadystatechange = function()函数将如何评估。是不是xmlhttp.open()和xmlhttp.send()需要在返回评估之前执行?
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
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.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
我强烈建议你使用jQuery,即使你不熟悉它,至少其ajaxing轻松。 – Ashraf 2012-03-20 15:46:39