Blog: Tag Archives: ajax

Javascript – Ajax Function

Posted On:

function AjaxifyContent(PageURL, QueryString, LoadingMessage, UpdateDiv) {
	
    var xmlHttpReq = false;
	// Tag Suggest - need to append the search term
	
	if(QueryString=='GetTag=')
	{	var GetTag=document.search.searchTerm.value;
		QueryString = QueryString+GetTag;
		//Show Tags
		if (document.getElementById)
		{
			obj = document.getElementById('WriteTags');
			obj.style.display = "";
		}
	
	}
	
	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", PageURL+"?"+QueryString, true);
  	self.xmlHttpReq.open("POST", PageURL, true);
  	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   // self.xmlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	self.xmlHttpReq.setRequestHeader("Content-length", QueryString.length);
	//self.xmlHttpReq.setRequestHeader("Connection", "close");
	
    self.xmlHttpReq.onreadystatechange = function() {
    	if (self.xmlHttpReq.readyState == 1) {
           	document.getElementById(UpdateDiv).innerHTML = LoadingMessage;
			
        }	
        if (self.xmlHttpReq.readyState == 4) {
            document.getElementById(UpdateDiv).innerHTML = self.xmlHttpReq.responseText;
			
        }
    }
    
	self.xmlHttpReq.send(QueryString);
}