/******************************************************************************* * ______________________________________________________ * * The "options" parameter is an anonymous object which includes the following * available options: * * params: Parameters for the requested url in the format p1=1&p2=0&p3=2 * meth: The request method. Can be "get" or "post". Default is "post". * async: Toggles asynchronous mode. Default is true. * startfunc: A function or list of functions to be called before the AJAX * request is made. A list of functions must be separated by the * semi-colon like this: "showLoad(); animateText(); hideDiv('divname')". * You can pass parameters into the functions. * endfunc: A function or list of functions to be called after a successful * AJAX request. Uses the same format as "startfunc". * errorfunc: A function or list of functions to be called when the AJAX request * is unsuccessful. Uses the same format as "startfunc". * * Returns true on success and false on failure. * * Example Usage: * callAjax( "rightdiv", "getData.php", { params:"id=12&name=sameer", meth:"post", async:true, startfunc:"elemOn('loading')", endfunc:"elemOff('loading'); elemOn('rightdiv')", errorfunc:"ajaxError()" } ); */ function callAjax( elemid, url, options ) { var params = options.params || ""; var meth = options.meth || "post"; var async = options.mode || true; var startfunc = options.startfunc || ""; var endfunc = options.endfunc || ""; var errorfunc = options.errorfunc || ""; if( startfunc != "" ) eval( startfunc ); var url_with_param = url+( params != "" ? "?"+params : "" ); //alert(url_with_param); loadXMLDoc(); //---------------------------------------------------------------- var xmlhttp function loadXMLDoc() { // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open(meth,url_with_param,async) xmlhttp.send('') } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") if (xmlhttp) { xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open(meth,url_with_param,async) xmlhttp.send() return false; }else { alert( "Your browser cannot perform the requested action. "+ "Either your security settings are too high or your "+ "browser is outdated. Try the newest version of "+ "Internet Explorer or Mozilla Firefox." ); return false; } } } function xmlhttpChange() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { //alert(xmlhttp.status); if (xmlhttp.status==200) { var objXML = xmlhttp.responseXML; var objXML1 = xmlhttp.responseText; //alert(objXML1); document.getElementById(elemid).innerHTML = objXML1; if( endfunc != "" ) eval( endfunc ); } else { document.getElementById(elemid).innerHTML = "Loading..."; //alert("Problem retrieving XML data") if( endfunc != "" ) eval( endfunc ); if( errorfunc != "" ) eval( errorfunc ); return false; } } else { // document.getElementById(elemid).innerHTML = "Loading..."; } } } //END OF AJAX FUNCTIONS.