var Class = { create: function() { return function() { this.initialize.apply(this, arguments); }; } }; var myXMLHttpRequest = Class.create(); myXMLHttpRequest.prototype = { url : null, myRequest : null, callBack : null, initialize : function (urltp,callBack) { this.url = urltp; this.myRequest = false; this.callBack = callBack; if(!this.myRequest){ try{ //IE6.0的 this.myRequest = new ActiveXObject("Msxml2.XMLHTTP"); if(!this.myRequest){ //其他的IE this.myRequest = new ActionXObject("Microsof.XMLHTTP"); } } catch(e){ //非IE浏览器 this.myRequest = new XMLHttpRequest(); } } }, callSever : function (){ if(this.myRequest){ this.myRequest.open("GET",this.url,true); this.myRequest.onreadystatechange = this.callBack; this.myRequest.send(null); } } }; var test = new myXMLHttpRequest('data.jsp',callBack); function callBack (){ //准备好了 if(test.myRequest.readyState==4) { var response = test.myRequest.responseText; alert(response); } }