Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Russ Michaels

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
r...@whitestonemedia.com 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:347681
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Rick Faircloth

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:r...@michaels.me.uk] 
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
r...@whitestonemedia.com 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:347683
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Russ Michaels

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
r...@whitestonemedia.com 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:r...@michaels.me.uk]
 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
 r...@whitestonemedia.com 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


Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Steve 'Cutter' Blades

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)

cfoutputscript type=text/javascriptvar 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-style-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 twocfoutput'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:347687
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Rick Faircloth

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)

cfoutputscript type=text/javascriptvar 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 twocfoutput'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:347688
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: Code from cfhtmlhead showing up in jQuery AJAX JSON data

2011-09-24 Thread Lists

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)
 
 cfoutputscript type=text/javascriptvar 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 twocfoutput'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