I'm trying to use AJAX to streamline the Rating Vote feature of Solspace Rating so the success or error code from the {exp:rating:insert_rating_vote}
tag.
In my {rating:entries} template I have this code for the up down voting links:
{exp:rating:rating_vote_stats rating_id="{rating_id}"}
{if not_already_voted}<span class="helpful"><strong>Was this review helpful?</strong><span class="voters"><a href="/vendor/rating-vote/{rating_id}/up/" class="yes">Yes</a> | <a href="/vendor/rating-vote/{rating_id}/down/" class="no">No</a></span><span class="ajax-response"></span></span>{/if}
{if already_voted}<span class="helpful"><strong>Was this review helpful?</strong><span class="ajax-response">Thanks for your vote</span></span>{/if}
{if total > 0}<span class="light people-like">{up_votes}/{total} people liked this review</span>{/if}
{/exp:rating:rating_vote_stats}
And the /vendor/rating-vote template those links point to contains this:
{exp:rating:insert_rating_vote
rating_id="{segment_3}"
allow_duplicates="no"
duplicate_check_guest_ip="no"
}
{if failure}Error!{/if}{if success}Thanks for your vote{/if}
{/exp:rating:insert_rating_vote}
This setup works as expected. When I click the link I go to that simple template which returns my failure or success message and the up/down vote is recorded and shows in my stats. I see:
Thanks for your vote
When I try to load the template via AJAX is doesn't work as expected.
I'm using this JS code:
$(".voters .yes, .voters .no") .click (function() {
var link = $(this).attr("href")
var $helpful = $(this).closest(".helpful");
$helpful.find(".ajax-response").load(link, function() {
$helpful.find(".voters").hide();
});
return false;
});
This works except the content loaded into my span is not the same as the ouput I got before. This is what I get in my template where I would expect the simple success message:
{"success":true,"failure":false,"message":"Your input is appreciated.","already_reviewed":false,"not_already_reviewed":true,"prior_review_count":0,"count":1}
Any advice on how to get this working?