Reputation: 749
This is the jquery code in ColdFusion index.cfm which is calling chkUsername of cfc file.
<script type="text/javascript">
chkUsernameUnique = function(theUsername){
$.getJSON("selectuser.cfc", {
method: 'chkUsername',
Username: theUsername,
returnformat: 'json'
}, function(isUsernameUnique){
if (isUsernameUnique == true) {
$("#theErrorDivID").html('Username is unique');
}
else {
$("#theErrorDivID").html('Please select a new username');
}
});
};
</script>
This is my component which is getting called from the cfm file.
<cfcomponent>
<cffunction name="chkUsername" returnformat="json" output="false">
<cfargument name="username" required="true">
<cfquery name="chkUsername" datasource="myDataSource">
SELECT ID FROM employees_login WHERE username = <cfqueryparam value="#arguments.username#" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfreturn yesNoFormat(chkUsername.recordCount) />
</cffunction>
</cfcomponent>
Nothing was getting displayed. I tried to check the error on fire bug and i am getting this error -
"NetworkError: 500 Internal Server Error:http://localhost:8500/workspace/UniqueUsername/selectuser.cfc?method=chkUsername&Username=admin&returnformat=json"
Upvotes: 0
Views: 1907
Reputation: 749
I was working on it from long time. Finally i got the answer. You need to write access="remote" in the cffunction tag like this-
<cfcomponent>
<cffunction name="chkUsername" returnformat="json" access="remote" output="false">
<cfargument name="username" required="true">
<cfquery name="chkUsername" datasource="myDataSource">
SELECT ID FROM employees_login WHERE username = <cfqueryparam value="#arguments.username#" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfreturn yesNoFormat(chkUsername.recordCount) />
</cffunction>
</cfcomponent>
Upvotes: 2
Reputation: 1977
Try replacing this: <cffunction name="chkUsername"returnformat="json" output="false">
with this: <cffunction name="chkUsername" returnformat="json" output="false">
Upvotes: 0