• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF-Ajax-Javascript Issue

New Here ,
Dec 29, 2008 Dec 29, 2008

Copy link to clipboard

Copied

Hello,

We have added a "recently viewed items" panel to the right side of our website.
In this panel we simply loop through the array of viewed items and present them
stacked up in the panel. The code for rendering the list of items is in a
separate CF template that is placed using an Ajax call within a <DIV>.

The problem is that the javascript is not executing in the recently viewed items
panel. For instance:

<script type="text/javascript">
var pr_page_id="#currItem#"; snippet(document);
</script>

This code is in the loop so that each iteration of an item should show the
"snippet." I can't see the javascript in the source code since it's inside a
<DIV> but the non-Ajax (CF) pages that use the same technique are getting
the correct snippet so I know that the code works and that the problem must come
from the use of the Ajax call.

Any ideas on a different way to call this so it will fire the javascripts
correctly.

Thanks much,
Jerry
TOPICS
Advanced techniques

Views

418

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

Inside a script tag for a cfm file you need to wrap every coldfusion variable individually with cfoutput tag, if you don't, it's passing, in your case #currItem# and not the value of the variable.

ie.
<script type="text/javascript">
var pr_page_id=<cfoutput>#currItem#</cfoutput>; snippet(document);
</script>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

CFWeb wrote:
> <script type="text/javascript">
> var pr_page_id=<cfoutput>#currItem#</cfoutput>; snippet(document);
> </script>

OR if you prefer a little less code, assuming you have more then one
variable in your script tag.

<cfoutput>
<script type="text/javascript">
var pr_page_id=#currItem#; snippet(document);
</script>
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

Thanks for your responses. The CFOUTPUT tags are present in my code I just did not include them in the text of the thread.

Any other ideas out there?

Jerry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

LATEST
why it is not working and how to fix it will likely depend on:
- how you make your ajax call
- which js framework, if any, you are using
- where and how your js functions are declared
- how you write you js in the included page
- specifically your snippet() function

so, please, elaborate a bit more...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation