cfwheels returning JSON that is commented out

215 views Asked by At

I'm developing in coldfusion with the cfwheels framework. I am trying to validate (via ajax) whether or not a user is logged in before submitting a form to a secure page that requires the user to be logged in. My ajax looks like this

function viewOnWebsite()
{
    params = {
        format: "json"
        , domain: '.#page.domain#'
    };

    $.ajax({
         url: '/user/login'
        , data: params
        , dataType: 'json'
        , type: 'POST'
        , success: function(result, status, jqXHR){
            if(result)
            {
                $('##frmViewOnWeb').submit();
            }
            else
            {
                alert('could not validate access to the website. You can try to refresh the page or log in');
            }
        }
        , error: function(jqXHR, status, error){
            alert(status);
            console.log(error);
        }
    });
}

And here is the controller (The parts you need to see)

<cfcomponent extends="Controller">
        <cffunction name="init">
            <cfset provides("html,json")>
        </cffunction> 
    <cffunction name="login"><cfscript>


        validationFunctionThatRedirectsInvalidUsers(true, 18);

            /* Check to see if the authtoken still exists in the db. */
            if(tokenIsValid(session.user.aToken))
            {
                response = {valid = "true"};
            }
            else
            {
                /* Create a new token */
                application.user.notImportantCode();

                /* Set the cookie */
                cookie.somethingYouDontNeedToKnow = {
                    value = session.user.aToken
                    , domain = params.domain
                };

                response = {valid = "true"};
            }

            renderWith(data = response, returnAs = "json");
        </cfscript></cffunction>

Please forgive the sloppiness of my code at this time.

Oddly enough my response from this function is giving me a commented out JSON string that looks like this:

//{"valid":true} 

Chrome, firefox, and IE can't parse this (haven't tried safari). Any help is appreciated.

Also the end game is to return true if the function was a success and false if it is not. therefore I want to set response to true or false and not a struct like I currently have. I was literally just trying things out since when I simply returned true I was getting a json string like this:

//{true}
1

There are 1 answers

1
Henry On BEST ANSWER

Most likely Prefix serialized JSON with "//" is enabled in CF Admin or Application.cfc.

http://www.petefreitag.com/item/720.cfm