/* * Name: * simpleVortalAjax * * Description: * This Library is used to do a request to the server and get * and display record using ajax. * * * * Preconditions/Input: * - * * Postconditions/Output: * * Stored Procedures: * * Libraries: * * Log : * 11/10/2008 Dipak A.Basantani */ var globalXMLHttpRequest; var globalDisplayId = ""; var globalNotation = ""; var globalMethod = 'get'; function simpleVortalAjax(){ this.xmlHttpRequestObj = undefined; this.notation = 'html'; // notation will be xml, html and json notation of ajax this.url = undefined; this.displayId = undefined; this.displayIdArray = new Array(); // this will be useful when json notation will be used. this.callBackFunction = undefined; this.method = 'get'; // // initialize all the required variables for the ajax request // this.initialize = function(url,notation,displayId,method) { this.xmlHttpRequestObj = this.getXmlHttpRequstObject(); this.notation = notation; this.displayId = displayId; this.method = method; // // following variables are only defined for IE - 6 // globalXMLHttpRequest = this.xmlHttpRequestObj; globalDisplayId = displayId; globalNotation = notation globalMethod = method; this.url = url; try{ // // IE-6 not allowing this operation. // this.stateChangeFunction.parentObj = this; this.xmlHttpRequestObj.parentObj = this; }catch(error){} this.xmlHttpRequestObj.onreadystatechange = this.stateChangeFunction; this.sendRequest(); }// end function initialize // // for getting xmlhttp request object // this.getXmlHttpRequstObject = function() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; }// end nested catch } }// end first catch return xmlHttp; }// END FUNCTION - getXmlHttpRequstObject // // send teh request to server // this.sendRequest = function () { if(globalMethod == 'post' || this.method == 'post') { var params; var onlyUrl; try{ onlyUrl = this.url.substr(0,this.url.indexOf("?")) params = this.url.substr((this.url.indexOf("?")+1),this.url.length); params += "&sid="+Math.random(); this.xmlHttpRequestObj.open("POST", onlyUrl, true); this.xmlHttpRequestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.xmlHttpRequestObj.setRequestHeader("Content-length", params.length); this.xmlHttpRequestObj.setRequestHeader("Connection", "close"); this.xmlHttpRequestObj.send(params); } catch(error) { var msg = "Please try again later!"; document.getElementById('sort_order_messsage').innerHTML = "
"+msg+"
"; return; } } else { this.url = this.url+"&sid="+Math.random(); this.xmlHttpRequestObj.open("GET",this.url,true); this.xmlHttpRequestObj.send(null); } }// end function sendRequest to server. // // on readystate change call the function. // this.stateChangeFunction = function() { var tempParentObj = this.parentObj ; try { if(tempParentObj.xmlHttpRequestObj.readyState==4) { if(tempParentObj.callBackFunction != undefined) { // call the front-end library function for call back. eval('this.callBackFunction('+tempParentObj.xmlHttpRequestObj.responseText+')'); } // else display html or json notation form. else { if(tempParentObj.notation == 'html') { if(tempParentObj.displayId != undefined) { document.getElementById(tempParentObj.displayId).innerHTML = tempParentObj.xmlHttpRequestObj.responseText; try{ if(typeof(callBackFunctionAfterHTML) == "function") { callBackFunctionAfterHTML(tempParentObj.displayId); } }catch(fne){} } } else if(tempParentObj.notation == 'json') { callBackFunctionAfterAjax(tempParentObj.xmlHttpRequestObj.responseText); return false; } }//end else.display json or html notation form. } } catch(error) { // // speciall code for IE - 6 // if(globalXMLHttpRequest.readyState==4) { if(globalNotation == 'html') { if(globalDisplayId != "") { document.getElementById(globalDisplayId).innerHTML = globalXMLHttpRequest.responseText; try{ if(typeof(callBackFunctionAfterHTML) == "function") callBackFunctionAfterHTML(globalDisplayId); }catch(fne){} }//end else.display json or html notation form. } else if(globalNotation == 'json') { callBackFunctionAfterAjax(globalXMLHttpRequest.responseText); } } return false; } }// end function onreadystatechange }// end class function simpleVortalAjax