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.


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


I guess the question is, why do you need the datasource name in your
javascript code?  Generally, only the server should need to know about that.

If the DSN name exists in the application scope already, you should be able
to reference it in your CFML code on the server, and thus you wouldn't need
to pass it as part of your ajax request.

-- Josh



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


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:326159
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