Simple Ajax

Posted by & filed under Javascript.

function setupSimpleAjax(){
	//instantiate the object
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	} else {
		// code for IE6, IE5
	 	return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
	
function AjaxGet(url){
	simple_xmlhttp=setupSimpleAjax();
	
	// Async function - need to pass 'true' as 3rd param below to fire this
	simple_xmlhttp.onreadystatechange=function(){
		if (simple_xmlhttp.readyState==4 && simple_xmlhttp.status==200){
			// get response from PHP file here;
			// use async just to allow the process to continue without waiting for the response
		}
	}

	simple_xmlhttp.open("GET",url,true);
	simple_xmlhttp.send();

	return true;
}

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Bitnami