Are you sending a query string or form message? Usually login is POST, not GET. But anyway.
I usually like to post a more structured answer, so you have the option of returning additional information to the user, such as an error message, but the following simple example is true / false. You can simply give the method a remote access attribute, for example:
<cfcomponent name="Login"> <cfset variables.dsn = "mydb" /> <cffunction name="tryLogin" access="remote" output="false" returntype="boolean"> <cfargument name="username" type="string" required="true"/> <cfargument name="password" type="string" required="true"/> <cfset var loginQuery = "" /> <cfquery name="loginQuery" datasource="#variables.dsn#"> SELECT * FROM users WHERE username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#"/> AND password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/> </cfquery> <cfif loginQuery.recordcount> <cfreturn true /> <cfelse> <cfreturn false /> </cfif> </cffunction> </cfcomponent>
Now that you have your CFC, your main script should work fine, with a few modifications:
function AttemptLogin(userName, password) { $.ajax({ url: 'login.cfc', data: {method: 'tryLogin', username: userName, password: password}, success: function(data) { if (data == true) { alert('true!');} else { alert('false!');} } }); };
As mentioned in another answer, if you are returning a complex data type, such as a structure or an array, you need to specify returnFormat for "json" and change your arg data, for example:
data: {method: 'tryLogin', returnFormat: 'json', username: userName, password: password}
source share