>I'll need to test an ajax post to validate if an account already exists in
>database. I'm using this code in action page:
>
><cfsetting showdebugoutput="no">
><cfprocessingdirective suppresswhitespace = "yes" pageencoding="ISO-8859-
>1">
><cfheader charset="iso-8859-1" name="Expires"
>value="#GetHttpTimeString(Now())#">
><cfcontent reset="true" type="text/plain;charset=ISO-8859-1">
><cfset rndTest = RandRange(90,99)>
><cfif rndTest MOD 2>
>    <cfoutput>#rndTest#</cfoutput>
><cfelse>              <<<<<<<<<< LOOK HERE WITHOUT CFOUTPUT
>    no
></cfif>
></cfcontent>
></cfprocessingdirective>
>
>Using that script returns(randomly) the "no" with 5 chars(maybe because
><tab> for tags alignment). Including "no" inside <cfoutput returns 3. Why
>CF doesn't works properly removing whitespace?

To answer your specific question, it's probably because when compiling to
byte code, the suppress whitespace will look at the tag structure of:

><cfif rndTest MOD 2>
>    <cfoutput>

And decide it's safe to remove that whitespacing, as it's most likely for
code formatting. However, with the statement:

><cfelse>
>    no

The formatting before the word "no" could be intended. The bottom line is
the suppresswhitespace option has to be conservative, to avoid removing
whitespacing that is necessary.

I think your best option is to rethink you're output a bit. If you revise
your code a bit, it will reduce the code and fix the problem. It'll also
speed things up:

<cfsetting showdebugoutput="no">
<cfheader 
        charset="iso-8859-1" 
        name="Expires" 
        value="#GetHttpTimeString(Now())#" 
        />

<cfset rndTest = RandRange(90,99)>
<cfif (rndTest MOD 2) eq 0>
        <cfset rndTest = "no" />
</cfif>

<cfcontent 
        reset="true" 
        type="text/plain;charset=ISO-8859-1"
        /><cfoutput>#rndTest#</cfoutput>

Quite frankly, I'm not sure why you're outputting what you are, but I'll
assume you have a reason.

-Dan

Reply via email to