I'm having issues with following code. I'm looking to validate an address(city,zip,state) and check it against what's in our database, which is called in the CFC.
When I have the dataFilter setting for the Ajax, it goes into the error and display "parseerror", and I do not see the string javascript return.
When I remove the dataFilter, in the console I see the javascript string return, but it always goes into the "else" for the success setting.
Anyone know what is going on? What am I doing wrong?
The CFC does return correctly according to Fiddler (true/false).
$.ajax({
type: "get",
url: "/component/validateLenderAddress.cfc",
data: {
method: "validateZipCityState",
returnFormat: "json",
zip:$('input[name*="zip"]').val(),
city:$('input[name*="city"]').val(),
state:$('input[name*="state"]').val()
},
async: false,
cache: false,
dataFilter: function(data) {
return $.parseJSON(data);
},
success:function(data) {
if (data) {
alert('Address Validated');
return true;
}
else {
alert('Address could not be validated');
return false;
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(ajaxOptions);
}
});
My CFC is
<cfcomponent output="false" extends="component.Database" hint="validates lender address lendermaint.inc">
<cffunction name="validateZipCityState" output="false" returnType="struct" access="remote">
<cfargument name="zip" type="string" required="true">
<cfargument name="city" type="string" required="true">
<cfargument name="state" type="string" required="true">
<cfset var local = structNew()>
<cfquery name="local.zipCodeList" datasource="#getDSN()#" username="#getUsername()#" password="#getPassword()#">
SELECT TOP 1 1
FROM ZipCode
WHERE zipCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.zip)#">
AND city = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.city)#">
AND stateShort = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.state)#">
</cfquery>
<cfreturn local.zipCodeList.recordCount EQ 1>
</cffunction>
Thanks!