well using your current method the vars will of course will only be
created and output once when application starts, so wont exist on any
subsequent requests, which I do not think is what you want if they are
JS variables you want them output on every page request in order for
them to be available to JS, so you would need to do it onrequestStart
or just by putting them in the actual html head.

Technically if there is no HEAD section then CF should not be trying
to insert the content, so in your CFC's you need to make sure you have
output disabled so that unnecessary content doesn't get added. You may
also need to make use of <cfsetting enablecfoutputonly="true"> is some
places as well.

Russ

On Sat, Sep 24, 2011 at 1:06 PM, Rick Faircloth
<[email protected]> wrote:
>
> Only onApplicationStart currently.
>
> I thought about using onRequestStart, but it needs to
> always be on the page, anyway, so I thought I'd do it once
> in the onApplicationStart routine.
>
> Is that a problem?
>
> Oh, wait... do you mean every "page request" or every
> AJAX "request" for data?
>
>
> -----Original Message-----
> From: Russ Michaels [mailto:[email protected]]
> Sent: Saturday, September 24, 2011 8:00 AM
> To: cf-talk
> Subject: Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data
>
>
> it is only happening onApplicationstart or is it being inserted into
> every request ?
>
> Russ
>
> On Sat, Sep 24, 2011 at 12:31 PM, Rick Faircloth
> <[email protected]> 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:347686
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to