Interesting solution, Tony.

I realized when I tried James' approach of placing my js in external .cfm
files
that the js didn't execute as expected.  When I placed the js code directly
in the calling page again, it acted normally.  It appears that the .cfm
extension
caused some change in interaction between the cf and js code and the
results.

So, I tried putting the js code into external .js files and hard-coding the
datasource name into the js values and it worked properly.

However, putting the application.dsn variable into a .cfm file inside the js
code
did expose the datasource name in the source code.

So, I tried your approach and put this after the link to the main jQuery
file:

<cfoutput>
        <script type="text/javascript">
                $.dsn = '#application.dsn#';
        </script>
</cfoutput>

Then for the external js file, I used:

values = { dsn:  $.dsn }

that worked fine, but when I viewed the source code for calling page,
I could still see:

<script type="text/javascript">
        $.dsn = "myDatasourceName";
</script>

Is there a way to hide the datasource name in the source code?

As I look through the js code in my calling page, the datasource name
is still visible in other code, as well.

I don't see a way to prevent that from happening.

What am I missing here?

Thanks,

Rick



-----Original Message-----
From: Tony Bentley [mailto:[email protected]] 
Sent: Wednesday, September 09, 2009 1:44 PM
To: cf-talk
Subject: Re: How to handle CF variables in JS (jQuery) external files...


Simply declare your JS vars at the top of the page and reference them in
your js file.

<cfoutput>
<script>
$.datasource = '#application.datasource#';

$.root = '#application.root#';

$.user = '#session.user#';

</script>
</cfoutput>

Then load your js files underneath. This way, your browser can cache your js
files as normal and you are not loading unnecessary external files on each
page request. 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:326155
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