0 Replies Latest reply on Apr 19, 2007 1:18 PM by yterus

    XMLHttpRequest issue with ColdFusion

      Hello All,

      I am following this tutorial that was originally written for PHP and trying to modify it for CF.


      The Modifications are as follows:

      var url = "Agency.cfc?method=StepSix&AgencyName="

      the Agency CFC method looks like this:

      <cffunction name="StepSix" access="remote" hint="Function that deletes an existing Agent">
      <cfargument name="AgencyName" type="any" required="yes">

      <cfinvoke component="Aims.Cfc.com.vergedata.surity.database.TblAgency" method="BasicSearch" returnvariable="qryAgency">
      <cfinvokeargument name="AgencyName" value="#Arguments.AgencyName#"/>

      <cfinvoke component="Aims.Cfc.com.vergedata.surity.database.TblAgencyAddress" method="BasicSearch" returnvariable="qryAgencyAddress">
      <cfinvokeargument name="AgencyId" value="#qryAgency.AgencyId#"/>

      <cfset xmloutput='<?xml version="1.0" standalone="yes"?><city>'&qryAgencyAddress.AgencyAddressCity&'</city><state>'&qryAgencyAd dress.AgencyAddressState&'</state>' >
      <cfprocessingdirective suppresswhitespace="yes"><cfheader name="Content-Type" value="text/xml"><cfoutput>#xmloutput#</cfoutput>


      ------------------------------------------------------------------------------------------ -------------------------------
      ------------------------------------------------------------------------------------------ -------------------------------

      The javascript error occurs on this line of code where i am grabbing the xml content between the tags and inserting them into variables.

      var city = xmlDocument.getElementsByTagName('city').item(0).item(0).firstChild.data

      my assumption is that i am doing something wrong when initiallizing the XML. It looks like the javascript doesnt reconize that it is being fed xml.

      If you have any idea why this may be happening, please let me know.

      here is the HTML page

      ------------------------------------------------------------------------------------------ -------------------------------
      ------------------------------------------------------------------------------------------ -------------------------------

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns=" http://www.w3.org/1999/xhtml" >


      <title>ZIP Code to City and State using XmlHttpRequest</title>

      <script language="javascript" type="text/javascript">

      var url = "/Aims/Cfc/com/vergedata/administration/applicationlogic/Agency.cfc?method=StepSix&Agency Name="; // The server-side script

      function handleHttpResponse() {

      if (http.readyState == 4) {

      // Use the XML DOM to unpack the city and state data
      var xmlDocument = http.responseXML;

      var city = xmlDocument.getElementsByTagName('city').item(0).item(0).firstChild.data;
      var state = xmlDocument.getElementsByTagName('state').item(0).firstChild.data;
      document.getElementById('city').value = city;
      document.getElementById('state').value = state;

      // Split the comma delimited response into an array

      //results = http.responseText.split(",");

      //document.getElementById('city').value = trimString(results[0]);

      //document.getElementById('state').value = trimString(results[1]);



      function updateCityState() {

      var zipValue = document.getElementById("zip").value;
      http.open("GET", url + escape(zipValue), true);

      http.onreadystatechange = handleHttpResponse;



      function getHTTPObject() {

      var xmlhttp;


      @if (@_jscript_version >= 5)

      try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

      } catch (e) {

      try {

      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

      xmlhttp = false;




      xmlhttp = false;

      @end @*/

      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

      try {

      xmlhttp = new XMLHttpRequest();

      } catch (e) {

      xmlhttp = false;



      return xmlhttp;


      function trimString (str) {
      str = this != window? this : str;
      return str.replace(/^\s+/g, '').replace(/\s+$/g, '');

      var http = getHTTPObject(); // We create the HTTP Object




      <form action="post">


      ZIP code:

      <input type="text" name="zip" id="zip" onblur="updateCityState();" />



      <input type="text" name="city" id="city" />


      <input type="text" size="2" name="state" id="state" />