Ajax访问原型

View Code
 1 var xmlHttp = null;
 2 if (window.XMLHttpRequest) {
 3     //FireFox,Mozillar,Opera,Safari,IE7,IE8
 4     xmlhttp = new XMLHttpRequest();
 5 }
 6 else 
 7     if (window.ActiveXObject) {
 8         //针对IE6,IE5.5,IE5
 9         //两个可以创建XMLHttpRequest对象的控件名称,保存在一个js数组中
10         //排在前面的版本较高
11         var activeName = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
12         for (var i = 0; i < activeName.length; i++) {
13             try {
14                 //取出一个控件名进行创建
15                 //如果创建失败抛出异常继续创建
16                 xmlhttp = new ActiveXObject(activeName[i]);
17                 break;
18             } 
19             catch (e) {
20             }
21         }
22     }
23 xmlhttp.open("GET", xmlurl, true);
24 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
25 xmlhttp.onreadystatechange = function(){
26     if (xmlhttp.readyState == 4) {
27         //判断http交互是否成功
28         if (xmlhttp.status == 200) {
29             function a(){//somthing}
30             }
31         }
32     }
33 }
原文地址:https://www.cnblogs.com/dengnan/p/2883040.html