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
{
animateResults();
}
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
// http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
// http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
$("#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');
});
}
});