全部现代浏览器(IE7+、Firefox、Chrome、Safari 以及 Opera)均内建 XMLHttpRequest 对象。浏览器
variable=new XMLHttpRequest();
variable=new ActiveXObject("Microsoft.XMLHTTP");
为了应对全部的现代浏览器,包括 IE5 和 IE6,请检查浏览器是否支持 XMLHttpRequest 对象。若是支持,则建立 XMLHttpRequest 对象。若是不支持,则建立 ActiveXObject :spa
var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }