纯JS的ajax实例


 1 <script type="text/javascript">
 2 function createxmlHttp(){
 3 var xmlhttp; 
 4 //创建xmlhttp对象
 5 if (window.XMLHttpRequest) 
 6     xmlhttp=new XMLHttpRequest(); 
 7 else 
 8     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 9 }
10 
11 function createRequest(){
12 xmlhttp.onreadystatechange=callbacksuccess    //回调函数
13 xmlhttp.open('post',url,true(是否异步));     //发送ajax
14 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
15 xmlhttp.send(data);  //get时data为null
16 }
17 function callbacksuccess()
18 {
19   if (xmlhttp.readyState==4 && xmlhttp.status==200)
20      {
21         // 成功后执行的代码
22         documrnt.getElementById("textarea").value = xmlhttp.responseText;  //服务器返回数据为xmlhttp.responseText
23      }
24 }
25 createRequest();
26 </script> 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM