cfajaxproxy / cfc / javascript issue (returned number being altered)
Ok, guys, this is a wierd one. I am using CF8 with IIS, and am using the cfajaxproxy method to call a CFC using javascript. In this particular case, it is a very simple CFC with one method used to determine if a string passed (an email address in this case) exists in the database. The value returned to the JS function is just the recordcount of very a simple query in the CFC.
The problem is this: In the JS function handling the the returned result, the returned result does not match what is being passed from the CFC!
Specifically, if you alert of otherwise display the result in the JS, it somehow has ".02009955946" appended to it. (So if the CFC recordcount is 0, the JS sees "0.02009955946", if the CFC recordcount is 1, the JS sees "1.02009955946" etc.) I have added code to the CFC to report the returned value independently (via cfmail), and it is being returned from the CFC correctly. But alerting the value returned to the JS function results in the odd results mentioned above.
Here is the actual code:
From the CFC:
<cfcomponent displayname="userEmailCheck">
<cffunction name="userEmailDupeCheck" access="remote" returntype="numeric" hint="This function determines if a submitted user email address already exists in the DB.">
<cfargument name="emailAddress" type="String" required="false">
<cfset var numDupeEmail = 0>
<cfif arguments.emailAddress NEQ "">
<cfquery name="checkEmailinDB" datasource="#request.dsn#">
select wcs_user_id
from wcs_user_tb
where wcs_login = '#arguments.emailAddress#'
</cfquery>
<cfset numDupeEmail = checkEmailinDB.recordcount>
</cfif>
<cfreturn numDupeEmail>
</cffunction>
</cfcomponent>
And here is the relevant JS code from the CFM page:
...
<cfajaxproxy cfc="cfcs.userEmailCheck" jsclassname="userEmailCheckProxy">
<script>
function emailCheckSuccess(theResult)
{
alert(document.getElementById('email').value);
alert(theResult);
if (document.getElementById('email').value != '' && theResult > 0)
{
alert('This email address already exists in the database.\n\nPlease enter an unique address if you wish to add a new user.');
document.getElementById('email').select();
}
}
function theEmailDupeCheck(emailAddress)
{
var instance = new userEmailCheckProxy();
instance.setCallbackHandler(emailCheckSuccess);
instance.userEmailDupeCheck(emailAddress);
}
</script>
...
[inside the cfform on the page...]
<cfinput name="email" id="email" type="Text" size="35" value="" defaultValue="" required="Yes" message="Please enter Email address" onBlur="theEmailDupeCheck(this.value);">
Has anyone seen this before? I can manipulate the returned JS value to trim the extraneous garbage, but I am concerned that it shouldn't be there in the first place.
Any ideas as to why this happening???
Thanks in advance,
David
