gjunge / rateit.js

Rating plugin for jQuery. Fast, Progressive enhancement, touch support, icon-font support, highly customizable, unobtrusive JavaScript (using HTML5 data-* attributes), RTL support, supports as many stars as you'd like, and also any step size.
MIT License
161 stars 45 forks source link

Examples page request #21

Closed ScotsScripts closed 6 years ago

ScotsScripts commented 6 years ago

Great plugin! Thank you.

I have two sets of review stars for an item. One is the "overall rating" and the other is "my rating" - allows people to see how they rated the item. I'd like to use ajax/jquery to update the overall rating when someone rates or updates their rating in the "my rating" section.

No problem with ajax in getting the rating to save in the back end, but I'm having trouble getting the "overall rating" to update to reflect the new numbers.

Will you consider adding an example where rateit is being set by a json string? I have been experimenting with the way you use the buttons to dynamically set values but I'm not getting anywhere.

gjunge commented 6 years ago

Hi @ScotsScripts ,

The code you should be calling in the end should be really something similar to

function updateOverallRating(myjsonresponse) 
{
   /// assuming that myjsonresponse looks like { newrating: 4.3 , ...more stuff ... }
   var newoverallrating = myjsonresponse.newrating;
   //assuming your overall rating element is call id="OVERALLRATING"
   $('#OVERALLRATING').rateit('value', newoverallrating);
}

If this doesn't help you, please post the part of the code that needs to be updated.