Ajax callback function

This is a simple AJAX function that executes a callback function when it gets the data from the given URL. The callback function should accept a string parameter

 
	function doAJAX(queryString, url, callbackFunction){
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari
	  if (window.XMLHttpRequest) {
	    self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // IE
	  else if (window.ActiveXObject) {
	    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  self.xmlHttpReq.open('POST', url, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() {
	    if (self.xmlHttpReq.readyState == 4) {
	      eval(callbackFunction+'(self.xmlHttpReq.responseText);');
	    }
	  }
	  self.xmlHttpReq.send(queryString);
	}
 

No Comments



Leave a comment