AJAX in plain Javascript, without jQuery

Written By Sanjir Habib On Apr-26th, 2021
Here's the simplest code. You won't find it elsewhere.
function ajax_get(url,callback){
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == XMLHttpRequest.DONE) {
			if (xmlhttp.status == 200) return callback('ok',xmlhttp.responseText);
			else return callback('error',xmlhttp.responseText);
		}
	};
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
To call it...
ajax_get('my/url/?param=val',function(result,data){
	if(result=='error') { /*error handler*/ }
	/* process data */
})