Good job "Steve"!! On Sep 24, 2011, at 8:18 AM, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
> > Duh... Steve, what you and Russ have pointed out makes perfect sense. > My initial thought was to use onRequestStart, but for some reason > decided to use onApplicationStart, which wouldn't work for every page. > > I guess I was thinking of just creating the variables once for > global use, rather than focusing on the fact that I needed to create > them for every page. > > Thanks for the tip! (...and the code, Steve! :o) > > And yes, it's CF9... > > Rick > > -----Original Message----- > From: Steve 'Cutter' Blades [mailto:cold.fus...@cutterscrossing.com] > Sent: Saturday, September 24, 2011 8:41 AM > To: cf-talk > Subject: Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data > > > You wouldn't put it in onApplicationStart, but onRequest (cf9+). > onRequest is only triggered on cfm requests, whereas a cfc would trigger > onCFCRequest. (I am assuming your Ajax requests are going to a CFC) > > Set up your js vars in onApplicationStart > > <cfscript> > application.siteDetail = {"js_sitename"=application.sitename, > "js_website"=application.website, > "js_site_manager_dsn"=application.site_manager_dsn, > "js_client_dsn"=application.client_dsn } > </cfscript> > > Then, in your onRequest (though some header include custom tag, included > at the page level, would be better and give greater flexibility) > > <cfoutput><script type="text/javascript">var siteDetail = > #SerializeJSON(application.siteDetail)#;</script></cfoutput> > > Then, in your JS, access the vars from the JS obj > > ... // some JQuery Ajax call data object > data: $.extend(true,{},siteDetail,{someArg:1,someArg2:'myArg'}) > > There's probably many ways to handle all of this, but putting the output > in your onApplication or onSession methods is not the way to go. > > Steve 'Cutter' Blades > Adobe Community Professional > Adobe Certified Expert > Advanced Macromedia ColdFusion MX 7 Developer > ____________ > http://cutterscrossing.com > > > Co-Author "Learning Ext JS 3.2" Packt Publishing 2010 > https://www.packtpub.com/learning-ext-js-3-2-for-building-dynamic-desktop-st > yle-user-interfaces/book > > "The best way to predict the future is to help create it" > > > On 9/24/2011 7:31 AM, Rick Faircloth wrote: >> Ok... something to talk about besides $20/hr (which may look >> really good, depending on how hungry you are...) >> >> I recently started using cfhtmlhead in onApplicationStart to put >> the following CF/JS in the head of each page to translate my CF >> site variables to JS: >> >> <cfset js_sitename = application.sitename /> >> <cfset js_website = application.website /> >> <cfset js_site_manager_dsn = application.site_manager_dsn /> >> <cfset js_client_dsn = application.client_dsn /> >> >> <cfoutput> >> >> <script> >> >> var js_sitename = '#js_siteName#'; >> var js_website = '#js_website#'; >> var js_site_manager_dsn = '#js_site_manager_dsn#'; >> var js_client_dsn = '#js_client_dsn#'; >> >> </script> >> >> </cfoutput> >> >> However, I just coded a page to load its content via jQuery AJAX >> which accesses a CFC method which uses cfSaveContent to generate >> the page.s HTML and then saves that to a document, which is then loaded >> via jQuery AJAX. >> >> After cfSaveContent does its thing, I send a 'Success' message >> in JSON back to the AJAX call. But this wasn't working. I've written >> this routine hundreds of times, so I know nothing was wrong with the >> AJAX code. >> >> It turns out that the JS above in between the two<cfoutput>'s was >> being sent back in the JSON, which was causing the message being sent >> back to the AJAX call to not just be 'Success', which would trigger >> the page HTML loading. >> >> Why would the above JS show up in the JSON data and what can I do about >> it? Taking the cfhtmlhead functionality out of the application.cfc's >> onApplicationStart routine and putting it manually in the head of the >> document solved the problem, but I enjoyed being able to insert the >> variable routine into the head of each page automatically. >> >> Thoughts? Suggestions? >> >> For $20 an hour? :o) >> >> Rick >> >> >> >> > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:347689 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm