ajax 即Asynchronous JavaScript and XML 异步的JavaScript 和 xml
优势:局部刷新页面数据,不用整个页面都刷新
实例:
<html>
<head>
<script>
function Ajax(){
var xmlhttp;
if(window.XMLHttpRequest){//针对IE7+, Firefox, Chrome, Opera, Safari等浏览器
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");//针对IE5,IE6等浏览器
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("xyp").value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/test/xyp.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="text" id="xyp" value="">
</body>
</html>