ajax学习小结

来源:互联网 发布:淘宝巴巴爸爸是正品吗 编辑:程序博客网 时间:2024/05/16 09:57

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>

1 0
原创粉丝点击