日期:2014-05-16 浏览次数:20714 次
var ajax = {//xmlhttp request tryList:function(){ var xhr = null; for(var i=0;i<arguments.length;i++){ var lambda = arguments[i]; try{xhr = lambda();break;}catch(e){} } return xhr; }, init:function(){ return this.tryList( function(){return new ActiveXObject('MSXML2.XMLHttp.6.0');}, function(){return new ActiveXObject('MSXML2.XMLHttp.3.0');}, function(){return new XMLHttpRequest();}, function(){return new ActiveXObject('MSXML2.XMLHttp.5.0');}, function(){return new ActiveXObject('MSXML2.XMLHttp.4.0');}, function(){return new ActiveXObject('Msxml2.XMLHTTP');}, function(){return new ActiveXObject('MSXML.XMLHttp');}, function(){return new ActiveXObject('Microsoft.XMLHTTP');} ) || null; }, post:function(sUrl,sArgs,bAsync,fCallBack,errmsg){ var xhr = this.init(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.responseText){ if(fCallBack.constructor==Function){fCallBack(xhr);} }else{ //alert(errmsg); } } }; xhr.open('POST',encodeURI(sUrl),bAsync); xhr.setRequestHeader('Content-Length',sArgs.length); xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xhr.send(sArgs); }, get:function(sUrl,bAsync,fCallBack,errmsg){ var xhr = this.init(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if(xhr.responseText){ if(fCallBack.constructor==Function){fCallBack(xhr);} }else{ alert(errmsg); } } }; xhr.open('GET',encodeURI(sUrl),bAsync); xhr.send('Null'); } } var url = "http://218.94.82.38/getGoodsListByJson.shtml?cust_no=201286"; var callback = function(xhr) { alert(xhr.responseText) } ajax.get(url,true,callback,"无响应内容");