I'm new to jQuery and am trying to create a login page that will do an Ajax call to a CFC that simply returns true or false on whether login was successfull. My call is making it to the CFC with my arguments correctly, but what's getting returned is the problem. If I set my datatype in jQuery to be "html", I see what looks like a copy of my entire page in html along with the "true" value I'm looking for. But if I try setting it to "json" nothing happens. I'm on ColdFusion 9, jQuery 1.6.2.
My jQuery function:
$(function() { $('.error').hide(); $(".button").click(function() { // validate form here $('.error').hide(); var name = $("input#username").val(); var pass = $("input#password").val(); if (name == "") { $("label#username_error").show(); $("input#username").focus(); return false; } else if (pass == "") { $("label#password_error").show(); $("input#password").focus(); return false; } else { var bodyContent = $.ajax({ url: "cfc/Login.cfc?method=tryLogin&returnFormat=JSON", global: false, type: "POST", data: {username:name,password:pass}, dataType: "json", async:false, success: function(msg){ alert(msg); } } ).responseText; } }); }); My CFC code, VERY simple, I'm just trying to get this to return correctly for now:
<cfcomponent name="Login" output="false"> <cffunction name="tryLogin" access="remote" output="false"> <cfargument name="username" type="string" required="true"/> <cfargument name="password" type="string" required="true"/> <cfset var result = true /> <cfreturn result /> </cffunction> </cfcomponent>