Posted At : March 25, 2010 1:48 PM | Posted By : Admin
Related Categories:
Ajax,
Web20,
Coldfusion,
jQuery
Ok, I've been at this for a couple of hours now. I thought I was on the right track, but it looks like I'm still a bit lost :(
I have a modal login form using jquery and colorbox plugin.
Here is a snippet of my jquery ajax call:
$j.ajax({
url: 'cfc/security.cfc?method=login',
data: datastring,
dataType: 'json',
success: function(data) {
var response = eval(data);
console.log(response.MESSAGE);
$j('.ajaxMsg').css({"display":"block"}).html(data);
$j.fn.colorbox.resize();
}
});
When calling this CFC from a URL using the correct parameters, I get this:
{"MESSAGE":"Verified! Logging in...","FNAME":"John","LNAME":"Smith","VALID":true}
This is exactly what I want.
However, when running the ajax call above I get:
<wddxPacket version='1.0'><header/><data><string>{"MESSAGE":"Verified! Logging in....","FNAME":"John","LNAME":"Smith","VALID":true}</string></data></wddxPacket>
And this is screwing me up.
Here is my CFC snippet:
<CFFUNCTION name="login" access="remote" returntype="string" output="false">
<cfargument name="username" type="string" required="Yes">
<cfargument name="password" type="string" required="Yes">
<cfargument name="stayLogged" type="string" required="no" default="no">
<CFSET myReturn = {}>
.... sql statements ...
if valid
<cfset myReturn.valid = "true">
<cfset myReturn.fname = #getLogin.fname#>
<cfset myReturn.lname = #getLogin.lname#>
<cfset myReturn.message = "Verified! Logging in....">
if invalid
<cfset myReturn.valid = "false">
<cfset myReturn.fname = "">
<cfset myReturn.lname = "">
<cfset myReturn.message = "Unverified! Please try signing in again.">
<cfset myReturn = serializeJSON(myReturn)>
<cfreturn myReturn>
</cffunction>
Ok...what am I doing wrong? :(