Skip to main content
Participant
December 29, 2008
Question

CF-Ajax-Javascript Issue

  • December 29, 2008
  • 3 replies
  • 452 views
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
This topic has been closed for replies.

3 replies

Inspiring
December 31, 2008
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/
Inspiring
December 30, 2008
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>
Participant
December 30, 2008
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
Participant
December 30, 2008
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>