HTML & Javascript

Ajax를 위한 간단한 JS 함수.

KJSR71 2015. 5. 27. 13:20

function _ajax(url, data, func, sync, type) {

var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4)  func(xmlhttp.responseText, xmlhttp.status == 200); };

xmlhttp.open(type ? type : "POST", url, !sync ? true : false);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.send(data);

}