// ***** ----------- ***** // ***** ajax.js ***** // ***** ----------- ***** /************************************************************************ * * Title: ajax() * Category: AJAX * File Name: ajax.js * WEB URL: * Created By: TAKE * Created Date: 2006-03-13 * Language: JavaScript * Description: Use AJAX(Asynchronous JavaScript + XML) * technology to download files and execute * callback function asynchronously. * * Syntax: ajax(sCallBack, URI, async) * * Parameters: sCallBack - callback function (no quotes) * URI - any URI where the source exists. * * Example: /example/ajax * * Browsers that support Ajax * -------------------------- * (Note that this is a general list, and support of Ajax * applications will depend on the features the browser supports.) * * Microsoft Internet Explorer version 5.0 and above, and browsers * based on it (Mac OS versions not supported) * Gecko-based browsers like Mozilla, Mozilla Firefox, SeaMonkey, * Epiphany, Galeon and Netscape version 7.1 and above * Browsers implementing the KHTML API version 3.2 and above, * including Konqueror version 3.2 and above, and Apple Safari * version 1.2 and above * Opera browsers version 8.0 and above, including Opera Mobile * Browser version 8.0 and above * (Reference: http://en.wikipedia.org/wiki/Ajax_%28programming%29) * * (Mac OS X 10.3 is required for the Apple Safari 1.2) * ***********************************************************************/ var AJAX_bPageLoaded = false; var AJAX_aCallBack = Array(); var AJAX_aRtnText = Array(); // --------------------------------------------------------- // function (ajax) // - your JavaScript program calls this function // --------------------------------------------------------- function ajax(sCallBack, sUri, bAsync, sParam) { var oAjax = createHttpRequest(); var sBrowser = getBrowser(); if (arguments[2] == null) { bAsync = true; } if (!sParam) { sParam = null; } // --- error messages --- var sError01 = ''; sError01 += 'ERROR: This function does not work on your browser\n\n'; sError01 += 'Please use one of the latest browsers. '; sError01 += 'Some PC compatible browsers: '; sError01 += 'IE5+, Netscape 7.1+, Firefox, etc. '; sError01 += 'MAC users are safe with Netscape or Firefox. '; sError01 += 'These are all free downloads!'; // --- unknown browser --- if (!oAjax) { alert(sError01); return false; } // --- callback function ------------------------------- // "oAjax.onload" is safer for opera, mozilla, konqueror // "oAjax.onload" does not work on IE // ----------------------------------------------------- switch (sBrowser) { case 'IE': oAjax.onreadystatechange = function(){ if (oAjax.readyState == 4 && oAjax.status == 200) { // --- session check --- var mixRtnValue = ''; if (oAjax.responseText.indexOf(" -1) { mixRtnValue = oAjax.responseXML; } else { mixRtnValue = oAjax.responseText; mixRtnValue = removeChar10(mixRtnValue); // see the definition if (mixRtnValue.indexOf('Log In Credentials')>-1){ mixRtnValue = 'ERROR: Session Timed Out.' } } if (sCallBack) { if (AJAX_bPageLoaded == true) { sCallBack(mixRtnValue); } else { AJAX_aCallBack.push(sCallBack); AJAX_aRtnText.push(mixRtnValue); } } } } break; default: oAjax.onload = function(){ // --- session check --- var mixRtnValue = ''; if (oAjax.responseText.indexOf(" -1) { var mixRtnValue = oAjax.responseXML; } else { var mixRtnValue = oAjax.responseText; mixRtnValue = removeChar10(mixRtnValue); // see the definition if (mixRtnValue.indexOf("Log In Credentials")>-1){ mixRtnValue = 'ERROR: Session Timed Out.' } } if (sCallBack) { sCallBack(mixRtnValue); } } break; } oAjax.open('POST', sUri, bAsync); oAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); oAjax.send(sParam); } function ajaxsubmit(sCallBack, sFormId, bAsync) { if (arguments[2] == null) { bAsync = true; } if (!sFormId) { sFormId = ''; } var aVar = Array(); var aVal = Array(); // --- input elements --- var cInput = document.getElementsByTagName('input'); for (var i=0; i