FrontEnd/JavaScript

AJAX Call 기본 형태..

행복한삶~!! 2013. 11. 20. 16:20

순수.. XMLHttpRequest 객체를 사용하여 ajax call 할때.. 

jQuery 나 prototype 사용하면.. 인터페이스가 다르다.. 

하지만... 그 내부를 까보면.. 아래와 같은 코드가 있다는거.. 

function ajaxUpdateServerVariable() 
{
	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");
	}
	
	// success 일때 호출되는 call back
	xmlhttp.onreadystatechange=function()
	{	  
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	  {
	    //update success	
	    //alert( xmlhttp.responseText );     
	  }
	}
	
	xmlhttp.open("GET","target_url.jsp?param=xxxx",true);
	xmlhttp.send();
}