Normally I just write my own to handle async calls my cfc's, however since
I've never used cfajaxproxy I thought I'd give it a try and now I'm
determined to make it work.
I am using cfajaxproxy to send some form data (as a js object) to my .cfc
which then runs a query and is supposed to send back a query object. However
when I invoke the method in the cfc my callback function is getting the
result as a NULL. In my callback I have alert(res) as the only item and I
expect to see [object] as the alert, but instead I get null.
I've thoroughly tested hitting the cfc from cf and everything works fine, I
get my query object returned from my method. However when I hit it from
javascript I don't get my query object returned back, just null.
Any help would be greatly appreciated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's my page which houses the form and the ajax proxy:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<cfsilent>
* **<!----[ Instantiate the main DAO component ]---->*
<cfset myDAO = createobject("component","components.appraisalDAO").init()/>
* **<!---[ Create a query object to hold all street types ]--->*
<cfset stType = myDAO.getStreetTypes()>
* **<!---[ Create a query object to hold all street directions ]--->*
<cfset stDir = myDAO.getStreetDirections()>
* **<!---[ Create a the proxy ]--->*
<cfajaxproxy cfc="components.appraisalDAO" jsclassname="appraisalDAO">
</cfsilent>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Page</title>
<script>
*var* objDAO = *new* appraisalDAO()*;*
objDAO.setErrorHandler(showError)*;*
objDAO.setCallbackHandler(handleResult)*;*
*function* findExactMatch()
*{*
*var* objForm = document*.*propInfo*;*
*var* propForm = *{};*
propForm.unitNum = objForm.unitNum.value*;*
propForm.streetNum = objForm.streetNum.value*;*
propForm.streetName = objForm.streetName.value*;*
propForm.streetType = objForm.streetType.options[
objForm.streetType.selectedIndex].value*;*
propForm.streetDir = objForm.streetDir.options[
objForm.streetDir.selectedIndex].value*;*
propForm.city = objForm.city.options[objForm.city.selectedIndex].value*;*
objDAO.getExactMatch(propForm)*;*
*return false;*
*}*
*function* handleResult(res)
*{*
* **// do something to handle the result** *
*alert*(res)*;*
*}*
*function* showError(e)
*{*
* alert(e.message);*
*}*
</script>
</head>
<body>
<cfform name="propInfo" onsubmit="return findExactMatch()">
<table>
<tr>
<td colspan="5">Choose City:
<cfselect name="city" size="1">
<option value = "">Choose City</option>
<option value = "">------------------</option>
<option value = "Chatham">Chatham</option>
<option value = "London" selected>London</option>
<option value = "Strathroy">Strathroy</option>
<option value = "StThomas">St. Thomas</option>
</cfselect>
<br><br>
</td>
</tr>
<tr>
<td>Unit #</td>
<td>* *Street #</td>
<td>Street Name</td>
<td>Street Type</td>
<td>Street Direction</td>
</tr>
<tr>
<td><cfinput type="Text" name="unitNum" required="No" size="5"></td>
<td>- <cfinput type="Text" name="streetNum" required="Yes" size="5"></td>
<td><cfinput type="Text" name="streetName" required="Yes" size="35"></td>
<td>
<cfselect name="streetType" size="1" query="stType" display="LongName"
value="LongName" queryPosition="Below">
<option value = "">Select One</option>
<option value = "">------------------</option>
<option value = "AVENUE">AVENUE</option>
<option value = "BOULEVARD">BOULEVARD</option>
<option value = "CRESCENT">CRESCENT</option>
<option value = "ROAD">ROAD</option>
<option value = "STREET">STREET</option>
<option value = "">------------------</option>
</cfselect>
</td>
<td><cfselect name="streetDir" size="1" query="stDir" display="LongName"value=
"LongName" queryPosition="Below">
<option value = "">If Applicable</option>
<option value = "">------------------</option>
<option value = "East" selected>East</option>
</cfselect>
</td>
</tr>
<tr>
<td colspan="5" align="center"><br><cfinput type="Submit" name="Submit"
value="Find Property"></td>
</tr>
</table>
</cfform>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's my component:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<cfcomponent name="appraisalDAO" output="false">
* **<!--- Initialize --->*
<cffunction name="init" access="public">
<cfreturn this />
</cffunction>
* **<!--- Return a query object of all street types in db --->** *
<cffunction name="getStreetTypes" access="remote" returntype="query">
<cfquery datasource="#Application.BaseDSN#" name="qryTypes">
SET NOCOUNT ON
SELECT LongName
FROM tbl_StreetTypes
GROUP BY LongName
ORDER BY LongName
SET NOCOUNT OFF
</cfquery>
<cfreturn qryTypes/>
</cffunction>
* **<!--- Return a query object of all street directions --->** *
<cffunction name="getStreetDirections" access="remote" returntype="query">
<cfquery datasource="#Application.BaseDSN#" name="qryDirections">
SET NOCOUNT ON
SELECT LongName
FROM tbl_StreetDirection
GROUP BY LongName
ORDER BY LongName
SET NOCOUNT OFF
</cfquery>
<cfreturn qryDirections/>
</cffunction>
* **<!--- [ Try to determine if there's an exact match. ] --->** *
<cffunction name="getExactMatch" access="remote" returntype="query">
* **<!--- [ struct values: unitNum, streetNum, streetName, streetType,
streetDir, city ] --->** *
<cfargument name="propForm" type="struct" required="true">
<cfset qryString = getExactMatchQry(propForm) /> *<!--- Get the query to
run. --->*
* **<!--- See if you can find an exact match. --->*
<cfquery datasource="#Application.BaseDSN#" name="qryGetMatch">
SET NOCOUNT ON
#PreserveSingleQuotes(qryString)#
SET NOCOUNT OFF
</cfquery>
<cfreturn qryGetMatch/>
</cffunction>
* **<!--- [ Create query text for finding an exact match on the address ]
--->** *
<cffunction name="getExactMatchQry" access="private" returntype="string">
* **<!--- [ struct values: unitNum, streetNum, streetName, streetType,
streetDir, city ] --->** *
<cfargument name="propForm" type="struct" required="true">
<cfscript>
address = getAddressParse(propForm)*;*
qryString = *"";*
qryString = *"SELECT** ** **MLS, ReCo, Address, NeighCode, Style,
BedRooms, Baths, BaseFin, SaleDate, Garage, SalePrice**"** **& CHR(10);*
qryString &= *"FROM** ** **tbl_#propForm.city#" *& CHR(10)*;*
qryString &= *"WHERE** **#address#" *& *CHR(10);*
qryString &= *"ORDER BY SaleDate DESC**"**;*
**
* **// Send back the qryString*
*return *qryString;
</cfscript>
</cffunction>
* **<!--- [ parse address, return a string. ] --->** *
<cffunction name="getAddressParse" access="private" returntype="string">
* **<!--- [ struct values: unitNum, streetNum, streetName, streetType,
streetDir, city ] --->** ** *
<cfargument name="propForm" type="struct" required="true">
<cfset address = "" />*<!--- [ set blank address ] --->*
* **<!--- [ get all street type variations ] --->*
<cfquery datasource="#Application.BaseDSN#" name="getStreetTypes">
SET NOCOUNT ON
SELECT CommonName
FROM tbl_StreetTypes
WHERE LongName = '#propForm.streetType#'
GROUP BY CommonName
SET NOCOUNT OFF
</cfquery>
* **<!--- [ loop though street type variations and create where clause ]
--->** ** *
<cfloop query="getStreetTypes">
<cfscript>
*if *(len(trim(address)))
address &= *"**#CHR(10)#OR ADDRESS LIKE **'";*
*else*
address &= *"**ADDRESS LIKE **'"*;
*// If there's a unit number*
*if *(len(trim(propForm.unitNum)))
address &= trim(propForm.unitNum) & *"**-**";*
*// Set the street number, name and type*
address &= trim(propForm.streetNum)*;*
address &= *" ";*
address &= trim(propForm.streetName)*;*
address &= *" ";*
address &= trim(CommonName)*;*
*// Set the street direction if it exists*
*if *(len(trim(propForm.streetDir)))
address &= *" "* & trim(evaluate(*"**application.streetDir.**"*
&propForm.streetDir
))*;*
address &= *"**%**'";*
</cfscript>
</cfloop>
* **<!--- Return address --->*
<cfreturn address />
</cffunction>
</cfcomponent>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334304
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm