Javascript / Jquery returns cfquery value of 'no' as false and 'yes' as true

前端 未结 2 1200
陌清茗
陌清茗 2021-01-21 17:03

I have an interesting problem. I Have a jquery ajax command to get data from a MySQL table (code to follow) When i then build my table values that should be yes are now true and

相关标签:
2条回答
  • 2021-01-21 17:42

    Hi All the comment Ageax was correct. Its a ColdFusion bug, I just added white space then trim the value later and it worked perfectly.

    Thanks very much

    0 讨论(0)
  • 2021-01-21 17:43

    You didn't mention which version of CF you're using, but ... there's one other option for queries in ColdFusion 2016+. Using the new query serialization settings in your Application.cfc will preserve the yes/no values as strings AND convert the query into a jQuery compatible array of structures - automatically. Obviously being application level settings, they'll apply to all queries within the application.

    • serialization.serializeQueryAs = "struct" - Automatically serialize all queries in the application as an array of structures (instead of the weird format CF uses by default).

    • serialization.preserveCaseForQueryColumn = true - Preserve the case of query column names (instead of converting everything to upper case).


    Application.cfc

    component {
        this.name = "Your_Application_Name_Here";
        this.serialization.serializeQueryAs = "struct";
        this.serialization.preserveCaseForQueryColumn = true;
    }
    

    DemoComponent.cfc

    <cfcomponent>
        <cffunction name="getData" access="remote" returntype="query">
    
        <!--- DEMO query. Note, manual queries MUST include column data types --->
        <cfset local.getItems = QueryNew("onceoff,exvat"
                                  , "varchar,varchar"
                                  , [{exvat : "yes",onceoff : "no"}]
                               )>
    
            <cfreturn local.getItems>
        </cffunction>   
    </cfcomponent>
    

    Result

    [{"onceoff":"no","exvat":"yes"}]
    
    0 讨论(0)
提交回复
热议问题