Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:52:21+00:00 2026-06-01T20:52:21+00:00

I have implemented a jquery plugin ratings widget. It works great until i make

  • 0

I have implemented a jquery plugin ratings widget. It works great until i make an ajax call to go get data. I need the plugin to add to the new elements.

I have tried to encapsulate the script in a function and call the function again on success but with no luck.

I also cant call the function without the success so that is my main issue.

How would I turn this into a function and call it on page load and ajax call. As you can see below i tried surrounding it.

function RatingWidget(e) {
    //    jQuery.noConflict();
    $(document).ready(function() {

        //we bind only to the rateit controls within the products div
        //$('#products .rateit').bind('rated reset', function (e) {
        $(".rateit").bind('over', function(event, value) {
            $(this).attr('title', value);
        });
        $(" .rateit").bind('rated reset', function(e) {

            var ri = $(this);
            // var msg = ri.next();
            // var msg = ri.next('div .ratemsg');
            var msg = $(this).parents().nextAll("div.ratemsg:first")


            //if the use pressed reset, it will get value: 0 (to be compatible with the HTML range control), we could check if e.type == 'reset', and then set the value to  null .
            var value = ri.rateit('value');
            //var productID = ri.data('productid'); // if the product id was in some hidden field: ri.closest('li').find('input[name="productid"]').val()
            var ratingid = ri.data('ratingid');
            //   var ratingtest = ri.data('ratingtest');
            var currentTime = new Date()
            var month = currentTime.getMonth() + 1
            var day = currentTime.getDate()
            var year = currentTime.getFullYear()
            var dateoftweet = (month + "/" + day + "/" + year)
            //  var dateoftweetparse = Date.parse(dateoftweet);
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()
            if (minutes < 10) {
                minutes = "0" + minutes
            }
            var timeoftweet = (hours + ":" + minutes + " ")
            //  var timeoftweetparse = Date.parse(timeoftweet);


            //maybe we want to disable voting?
            ri.rateit('readonly', true);

            $.ajax({
                url: '/Home/GetRating',
                //your server side script
                data: {
                    id: ratingid,
                    value: value,
                    tweetday: dateoftweet,
                    tweettime: timeoftweet
                },
                //our data
                type: 'POST',
                success: function(data) {
                    //$('#ratemsg').html(data);
                    msg.html("<B>The TweetId is " + ratingid + " the vote value is " + value + " " + dateoftweet + "  " + timeoftweet + "</b>");
                },
                error: function(jxhr, msg, err) {
                    //  $('#response').append('<li style="color:red">' + msg + '</li>');
                    msg.html(data);
                }
            });
        });

    });
}​​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:52:23+00:00Added an answer on June 1, 2026 at 8:52 pm

    The ready() event gets fired once the DOM is loaded; from the documentation:

    Specify a function to execute when the DOM is fully loaded.

    Rather than having your RatingWidget() function re-bind the ready event once the AJAX call is done, you should have it bind the elements, e.g.

    function RatingWidget() {
          $(".rateit").bind( ... )
    }
    $(document).ready(RatingWidget);
    

    As @adeneo mentioned, using jQuery’s on() method (documentation here) allows you to latch on to events matching a selector regardless of which elements existed when the event was binded, so if you add new elements matching the selector, the events will trigger for them as well. This will save you the trouble of figuring out when you need to re-bind event because your elements were replaced. e.g. you may call this once and not worry about it again:

    $(".rateit").on("over", function() { ... } )
    

    Since on works differently than bind, this might introduce a performance penalty, but that depends on how often you replace elements, how many elements there are etc. — it could just might be a performance gain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the Jquery cycle plugin on my page but I can't get
I have implemented the jQuery plugin Uploadify on a site, and for some reason
jQuery Uploadify plugin uses flash swf to upload files. I have implemented it on
I am using a counter plugin for jquery (http://wplayground.comuv.com/counter/) and have it implemented successfully
I have successfully implemented the scrollTo jQuery plugin which scrolls to the next div
I have implemented lightbox-plugin for jQuery of krewenki in a masterpage including all images.
I have implemented the image upload code using jquery php in my php web
I have played around and implemented JQuery cycle to create a carousel with images,
i am using jquery version 4.x and i have implemented column chooser on my
I have implement the exact same concept for my project- http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ My question is,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.