正文
$B.ajax = function(obj){ (obj.async === true) { 6 xhr.onreadystatechange = function() { 7 if(xhr.readyState ==4) { 8 callback(xhr.responseText); 9 } 10 } 11 } arr=[] ; 14 for(var i in obj.data) {arr.push(encodeURIComponent(i)+'='+encodeURIComponent(obj.data[i]));} (obj.method === 'get') {obj.url = obj.url.indexOf('?') ==-1 ? obj.url+'?rand='+Math.random()+'&'+obj.data : obj.url+'rand='+Math.random()+'&'+obj.data; 18 xhr.open(obj.method,obj.url,obj.async); 19 xhr.send(null); 20 } (obj.method === 'post') {obj.url =obj.url+'?rand='+Math.random(); 24 xhr.open(obj.method,obj.url,obj.async); xhr.send(obj.data); 27 } (obj.async === false) { 31 callback(xhr.responseText); 32 } 33 function callback (returnTxt) { 34 if(xhr.status == 200){ 35 obj.success(returnTxt); 36 } 37 } 38 }; $B.isFn = function(fn){ 42 if(fn && typeof fn =='function') { } ; 46 }; (typeof XMLHttpRequest !='undefined') { XMLHttpRequest(); 50 }else if(typeof ActiveXObject !='undefined') { 51 var version = [ 52 'MSXML2.XMLHttp6.0', 53 'MSXML2.XMLHttp3.0', 54 'MSXML2.XMLHttp' 55 ] 56 for(var i in version) { 57 try{ ActiveXObject(version[i]); 59 break; 60 }catch(e){ } 63 } 64 }else{ Error("您的系统或浏览器不支持XHR对象!"); 66 } 67 };