最も簡単なajaxの例


var xmlHttpReq; 
	//  XMLHTTP     
	function createXMLHttpRequest(){   
	    if(window.ActiveXObject){    // IE,//       window.ActiveXObject  
	        xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");   
			var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
			try {
				xmlHttpReq= new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e) {}
			}
						
	    }else if(window.XMLHttpRequest){    // Mozilla, Safari, ...
	        xmlHttpReq = new XMLHttpRequest();   
	    }   
	} 

function getXmlSend(flag,id){
			IDflag=flag;
			createXMLHttpRequest();
			var url="/.../xx.jsp?rand=" + Math.random() + "&id="+id+"&flag="+flag; 
			xmlHttpReq.open("GET",url,true);
			//xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8'); 
			xmlHttpReq.onreadystatechange = showResult;  //    showResult  
			xmlHttpReq.send(null); //         , Mozilla     null
/*
      :     xmlHttpReq.onreadystatechange = showResult;  xmlHttpReq.open("GET",url,false);
      http_request.send(null);      
var returntxt=unescape(http_request.responseText);

post      
xmlHttpReq.open("POST",url,true);
xmlHttpReq.send("         "); //eg:rand=" + Math.random() + "&id="+id+"&flag="+flag
*/
		}

function showResult(){    
            if(xmlHttpReq.readyState == 4){      
                if(xmlHttpReq.status == 200){
alert(xmlHttpReq.responseText);
        //       HTML          
//do something
}
             }      
         } 

ページや他の場所でgetXmlSend()メソッドを呼び出せばよい