aspx and rhythmyx issue

I’m trying to build a simple poll content type. It’s fairly simple, will be a poll question and a poll answer. THe poll question will contain a slot to allow user to insert answers. The template then assembles and allows the user to insert rhythmyx template onto other content types (i.e. generic page) and have the poll display on their page.

I’m using ASPX and Ajax calls to render the poll results. Works great in testing (outside of Rhythmyx). When I put all the javascript and ajax call scripts on the template and try to publish page through Rhythmyx, it tells me there’s an exception. The exception is occuring in the code below where i have bold and coloured ( $.ajax({ ). Does anyone have any thoughts on this? Unfortunately I do need this to be part of the templates and not an include because it is a page method and aspx won’t render it correctly otherwise AND there is a reference back to the page which Rhythmyx is going to have to enter (unless someone has a idea about that).

        $(document).ready(function() {
            var imgPoll = new Image();
            imgPoll.src = 'images/red-bar.png';

            if ($("#divVoted").length > 0) //Already voted
            else {
                $("#rdoPoll0").attr("checked", "checked"); //default select the first Choice
                // Add the page method call as an onclick handler for the Vote button.
                // For more details about how to use JQuery to call Asp.Net AJAX page methods refer follwoing blog posts
                $("#btnSubmit").click(function() {
                    $("#divPoll").css("cursor", "wait"); //show wait cursor inside Poll div while processing
                    $("#btnSubmit").attr("disabled", "true") //disable the Vote button while processing

                    var pID = $("input[id$=hidPollID]").val(); //get Poll ID
                    var cID = $("input[name='rdoPoll']:checked").val(); //get the checked Choice
                    var data = "{'pID':'" + pID + "', 'cID':'" + cID + "'}"; //create the JSON data to send to server
                   [B] $.ajax({[/B] //call the Page method using JQuery ajax
                        type: "POST",
                        url: "pollvbnew.aspx/UpdatePollCount",
                        data: data,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(msg)  //show the result
                                $("#divPoll").css("cursor", "default"); //remove the wait cursor
                                $("#btnSubmit").attr("disabled", "false") //enable the Vote button
                                $("div[id$=divAnswers]").fadeOut("fast").html(msg.d).fadeIn("fast", function() { animateResults(); });

            function animateResults() {
                $("div[id$=divAnswers] img").each(function() {
                    var percentage = $(this).attr("val");
                    $(this).css({ width: "0%" }).animate({ width: percentage }, 'slow');

I hear you can escape $ marks that aren’t velocity variable references with … so your call would become $.ajax… see this thread

Yeah I’ve already tried that but it still gives me an exception error. In the code I have $.ajax({ if i remove the ( then the exception goes away but this code no longer works.

did you try escaping the “(” and “)” ? - may sound stupid, but worse a trial…

and - as I have recommended in other post: use velocity escape tool
set your velocity variable $ajaxscript to string "$.ajax ( "

and try this: $esc.javascript($ajaxscript)

ecape the last “)” with \

From the Velocity User’s Guide

Alternately, the #literal script element allows the template designer to easily use large chunks of uninterpreted content in VTL code. This can be especially useful in place of escaping multiple directives.

#foreach ($woogie in $boogie)
  nothing will happen to $woogie

Renders as:

#foreach ($woogie in $boogie)
  nothing will happen to $woogie

So… try enclosing your aspx code in a #literal()-#end block.

Mike, your idea would be great… it the OP were outputting a value for a javascript string, but they’re not.

Thanks everyone for your help and suggestions. Although a number of your suggestions did escape my characters from velocity, unforunately it rendered the code not workable in ASPX. The last suggestion from Sam Rushing (I hope thats your name, apologies if its not) still threw an exception but together with Mike’s suggestion it did start to make me think about this differently and I came up with a solution that should have been obvious to me from the beginning as it seems so simple.

Ended up with this…

#set($ajaxCall=$dollarSign + ".ajax(")

Which rendered $.ajax( and velocity had no issues with anything else and aspx had no issues either.

So its working great, so again thanks everyone for your suggestions and help. Now I have a new challenge with this poll (trying to insert it using the rhythmyx insert template on a generic page) but I’ll post a new thread.


Dunno if this makes a difference, but there are already a bunch of escaped characters available through


For your needs you could use


I am a big fan of the quote characters as they prevent confusion when doing some trick stuff with outputting small JavaScript calls inside HTML elements… it kinda becomes quote soup. Sounds like you fixed it though.

I typically go really short with these to make them more readable, so I do something like:

#set($dq = $tools.esc.getQuote())

then I can use ${dq} any place I need double quotes, and eclipse makes them pink so they look different than everything else, and it’s much easier to read.