Using #application.dsn# in your component is a heckuva lot better than
passing it through the ajax call.  

To avoid using application scope in your component, you can pass it in when
you instantiate the component, as below:

In the component:

<cffunction name="init">
        <cfargument name="dsn">
                <cfset variables.dsn = arguments.dsn />  <!--- set a
reference to the datasource name --->
</cffunction>

<cffunction name="getStuff">
        <cfquery name="myQuery" datasource="#variables.dsn#">  <!---
reference the variables scope instead of application --->
        <!--- stuff --->
        </cfquery>
</cffunction>


Then when you instantiate:

<cfset
application.myComponent=createObject("component","path.to.component").init("
myDatasourceName") />



-- Josh



-----Original Message-----
From: Rick Faircloth [mailto:[email protected]] 
Sent: Wednesday, September 09, 2009 12:09 PM
To: cf-talk
Subject: RE: How to handle CF variables in JS (jQuery) external files...


Well...I was trying to following what I thought was a best practice for
components:  keep all variables out of the method and pass in the data from
the calling page.

In this case, the dsn has to be passed in via the ajax call, along with
other
values.  I guess I could hard-code the dsn value into the method, but I was
trying to avoid that, too.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326163
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to