var url = 'http://www.cfsinnovation.com/ajax-request.php'; var _my_ajax__current_form; var _my_ajax__current_name; var _my_ajax__handler_function; var _my_ajax__parameter; /** * Run the handler, with the form name, the element name, and the * request parameter object. */ function AjaxServerResponse(){ if(http.readyState == 4){ if(http.status == 200){ var response_xml = (new DOMParser()).parseFromString(http.responseText, "text/xml"); _my_ajax__handler_function(_my_ajax__current_form, _my_ajax__current_name, _my_ajax__parameter, response_xml); } else{ alert("There was an error retrieving the XML data packet: " + http.statusText); } } } /** * Call this function with... * 1 - The name of the form being called from. * 2 - The name of the element being called from. * 3 - The name of the response handler function. * 4 - The name of the server side request handler. * 5 - The parameter object, where each data member is passed * as a post parameter. */ function AjaxServerRequest(this_form, this_name, this_handler_function, this_ajax_handler, this_parameter){ /* Set identifing flag. */ var argument = 'ajax__request_type=1'; /* Set the process control parameters, and encode as URL argument. */ this_parameter.ajax__form = this_form; this_parameter.ajax__handler = this_ajax_handler; for(var parameter in this_parameter){ argument += ("&" + parameter + '=' + escape(this_parameter[parameter])); } /* Load the response. */ http.open("post", url); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); _my_ajax__current_form = this_form; _my_ajax__current_name = this_name; _my_ajax__handler_function = this_handler_function; _my_ajax__parameter = this_parameter; http.onreadystatechange = AjaxServerResponse; http.send(argument); } // The getHTTPObject() functon, courtesy of this page: // http://www.webpasties.com/xmlHttpRequest/step3.html // Usage: // var http = getHTTPObject(); // We create the HTTP Object function getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } /* * * Some helper functions for modules below..... * * */ /* Set a form element if data is available in the named tag. */ function xml_response_suggest_form(form, field, tag_name, xml){ var tag_xml = xml.getElementsByTagName(tag_name)[0]; if(tag_xml != null && tag_xml.firstChild != null && document.forms[form][field] != null){ document.forms[form][field].value = tag_xml.firstChild.data; } } /* Set a form element, from data in the named tag. If tag is empty or * missing, the form is cleared. */ function xml_response_set_form(form, field, tag_name, xml){ var tag_xml = xml.getElementsByTagName(tag_name)[0]; if(document.forms[form][field] == null){ return; } if(tag_xml != null && tag_xml.firstChild != null && document.forms[form][field] != null){ document.forms[form][field].value = tag_xml.firstChild.data; } else{ document.forms[form][field].value = ''; } } // We create the HTTP Object var http = getHTTPObject();