<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ajax1</title> 
<script>
function createXhr(){
 //判定浏览器类型处理第一种方法 
/*  var xhr;
 var str=window.navigator.userAgent;
 if(str.indexOf('MSIE')>0){
  xhr=new ActiveXObject('Microsoft.XMLHTTP');
 }else{
  xhr=new XMLHttpRequest();
 }
return xhr;
 */
 try{
    return new ActiveXObject('Microsoft.XMLHTTP');
  }catch(e){
   }
  try{
    return new XMLHttpRequest();
  }catch(e){
  }
   
};
window.οnlοad=function(){
  document.getElementById('button1').οnclick=function(){
           var xhr=createXhr();
           alert(xhr);
  } 
 };
</script>
</head>
<body>
<input type="button" id="button1" value="确定"></input>
</body>
</html>