views:

53

answers:

1

I have a page that uses a .post to submit to my cfc. I know the function works fine because the database is being updated but the alert that's being fired is the one in the 'else' statement.

Can any of you see why my return isn't firing the correct alert? Am I not capturing the return properly?

Some of my variables are hard coded for testing purposes...

The jQuery:

$(document).ready(function() {
    var theID = $('#window_one h1').attr('name').split("-")[1];
    var gateway = ("001");
//Populate the form
    $('#theText').attr('value', $('#window_one h1').html());
    $('#texteditform').submit(function(e){
         //stop the form submission
      e.preventDefault()                               
        var newText = $('#theText').val();
        //CFC
        $.post("cfc/engine.cfc?method=updateText&returnformat=json", 
            {text:newText, field:theID, gateway_id:gateway},
            function(res) {
                //Handle the result
                if(res == "true") {
                    alert("worked fine");
                } else {
                    alert("Didn't Work");
                }
            });
    });                        
});

</script>

The CFC

 <cffunction name="updateText" access="remote" output="no" returntype="boolean">


    <cfargument name="field" type="string" required="yes">
    <cfargument name="text" type="string" required="yes">
    <cfargument name="gateway_id" type="string" required="yes">
<cfquery datasource="#application.datasource#" username="#application.username#" password="#application.password#">
    UPDATE gateway
    SET #arguments.field# = <cfqueryparam value="#arguments.text#" cfsqltype="cf_sql_varchar">
    WHERE gateway_id = #arguments.gateway_id#
  </cfquery>
  <cfreturn true>
</cffunction>
+4  A: 

You have extra whitespace because of the way that CF generates its output. You need to make sure that the cfc itself is set to output="false"... May take some further wiggling around but that should get you started.

It's one of the more annoying features of CF

Daniel Sellers
That did the trick! <cfcomponent output="false"> in my cfc removed all the white space in my return. So now the question is, what else will that foul up that I don't know about yet... Thanks!
Ofeargall
Probably nothing. It's very rare that you don't want `output="false"` at the component level, and it really should be defaulted to false.
Peter Boughton
I posted this question with Raymond Camden at ColdFusionJedi, and he pretty much said the same thing. He always has the output on CFC's set to false in CF8. He did mention that it's not an issue in CF9.
Ofeargall