1 function createXHR () {//创建XMLHttpRequest对象 2 var xhr=null; 3 if(window.XMLHttpRequest){ 4 createXHR=createStandardXHR; // Firefox, Opera 8.0+,Safari,IE7+ 5 } 6 else{ 7 createXHR=createCompatibleXHR; // IE5、IE6 8 } 9 10 try{ 11 xhr=createXHR(); 12 } 13 catch(e){ 14 createXHR = createErrorXHR; 15 xhr=createXHR(); 16 } 17 18 return xhr; 19 } 20 21 function createStandardXHR(){ 22 return new XMLHttpRequest(); 23 } 24 25 function createCompatibleXHR(){ 26 return new ActiveXObject("Microsoft.XMLHTTP"); 27 } 28 29 function createErrorXHR(){ 30 alert("Your browser does not support XMLHTTP."); 31 return null; 32 }