Skip to main content
Known Participant
May 9, 2011
Question

not able to display result

  • May 9, 2011
  • 1 reply
  • 455 views

Hi below i had code that i copied from some where in internet and trying to execute but always result says Your login failed.message still component rturns true.

when i use alert i am seing wide page with all spaces  .

can some one will help me in this thanks

below i code

<html>
<head>
<script language="javascript" src="jquery-1.4.2.js"></script>
<script>
$(document).ready(function() {
    //grab the submit action
    $("#loginForm").submit(function(e) {

        //stop the form submission
        e.preventDefault()

        //get my values
        var uval = $("#username").val()

        //basic validation
        if(uval == '') return

        //disable the button
        $("#loginButton").attr("disabled",true)

        //Let the user know we are doing something       
        $("#result").html("Logging in...")
       
        //Send them to the CFC
        $.post("ajaxtest.cfc?method=tryLogin&returnformat=json",
                {username:uval},
                function(res) {
                    //Handle the result
                                   
                    res = jQuery.trim(res);                   
                    //alert(str);
                    if(res == "true") {
                        $("#result").html("Your login worked.")
                        //Do more here.
                    } else {
                        $("#result").html("Your login failed.")
                        $("#loginButton").removeAttr("disabled")
                    }
                });

    });
});
</script>
</head>

<body>

<form id="loginForm">
    username: <input type="text" name="username" id="username"><br/>   
    <input type="submit" value="Login" id="loginButton">
</form>

<div id="result"></div>

</body>
</html>

cfc......................

<cfcomponent name="Login">
   <cfset variables.dsn = "mydsn" />
   <cffunction name="tryLogin" access="remote" output="false">
      <cfargument name="username" type="string" required="true"/>

      <cfset var loginQuery = "" />

      <cfquery name="loginQuery" datasource="#variables.dsn#">
         SELECT name
         FROM emp
         WHERE
            name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#"/>
           
      </cfquery>

      <cfif loginQuery.recordcount>
         <cfreturn true />
      <cfelse>
         <cfreturn false />
      </cfif>
   </cffunction>
</cfcomponent>

This topic has been closed for replies.

1 reply

Inspiring
May 26, 2011

Try changing the following...

if(res == "true")

to

if(res == true) { // no quotes

If that doesn't work, then Alert the var 'res' and see what it's value is.