Ajax的异步处理

<html>
<head>
<title>www.xiongsheng.com, 熊胜的主页</title>
<script language="javascript">
var xmlHttp ;
function createXMLHttp(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest() ;
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") ;
}
}
function show(){
createXMLHttp() ;
xmlHttp.open("POST","content.htm") ;
xmlHttp.onreadystatechange = showCallback ;
xmlHttp.send(null) ;
}
function showCallback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var text = xmlHttp.responseText ;
document.getElementById("msg").innerHTML = text ;
}
}
}
</script>
</head>
<body>
<input type="button" onClick="show()" value="显示内容">
<span id="msg"></span>
</body>
</html>

你可能感兴趣的:(Ajax的异步处理)