views:

317

answers:

2

I am trying to write a script to check the availability of the passed username and email address, using ExtJs or JQuery; and Coldfusion 9 as server language. I have written one script but it's not working as intented.

Thanks Vicente

+1  A: 

This page has an easy example of checking username validity and availability along witha tutorial and explanation.

http://jqueryfordesigners.com/using-ajax-to-validate-forms/

Alex Sexton
+2  A: 

Something like this:

<cfcomponent hint="services.userService">
    <cffunction name="checkUser" access="remote" returnformat="json" returntype="struct">
        <cfargument name="username">
        <cfargument name="email">

        <cfset var result = { 'usernameExists' = true, 'emailExists' = true }>
        <!--- TODO: Check if the UN and Password exist --->
        <cfreturn result>
    </cffunction>
</cfcomponent>

Then:

<script>
$.getJSON("services/userService.cfc?method=checkUser", 
    { username = theUsername, email = theEmail }, 
    function(json) {
        if (json.usernameExists) { ... }
        if (json.emailExists) { ... }
    }
);
</script>
MightyE
Good answer, basically you want to pass the username to the server in the request, and the server can respond with "yes" or "no".
Jonathan Julian