大家都用过Ajax的异步交互,下面的代码中使用  "trycatch工厂模式"  来进行针对Ajax请求对象的变化点进行封装

<script type="text/javascript">
var createHttpRequest = function() {
var GetHttpRequest = [
function() {return new ActiveXObject("Microsoft.XMLHTTP");},
function() {return new XMLHttpRequest();}
];
for(var ele in GetHttpRequest) {
try {
GetHttpRequest[ele]();
} catch {
continue;
}
this.createHttpRequest = GetHttpRequest[ele]();
return GetHttpRequest[ele]();
}
      throw new Error("这些对象都不能用!");
}
</script>

  

  

05-13 04:50