0

Any reason why this isn't running when clicked? I can't seem to figure it out.

<button id="button-container-like" onclick="rate($(this).attr(\'id\'))"><span class="thumbs-up"></span>Like</button>

<script>
function rate(rating){
var data = 'rating='+rating+'&id=<?php echo $eventId; ?>&userid56=<?PHP echo $userid55; ?>';

$.ajax({
   type: 'POST',
   url: 'includes/rate.php', //POSTS FORM TO THIS FILE
   data: data,
   success: function(e){
   $(".ratings").html(e); //REPLACES THE TEXT OF view.php
}
});
}
</script>
1
  • well, are you getting any errors? Commented Nov 5, 2013 at 23:24

2 Answers 2

1

here you go:

<button id="button-container-like" ><span class="thumbs-up"></span>Like</button>

<script>
    jQuery(document).ready(function () {

        $("#button-container-like").click(function() {
            rate($(this).attr("id"));
        });

        function rate(rating) {
            var data = 'rating=' + rating + '&id=<?php echo $eventId; ?>&userid56=<?PHP echo $userid55; ?>';

            $.ajax({
                type: 'POST',
                url: 'includes/rate.php', //POSTS FORM TO THIS FILE
                data: data,
                success: function(e) {
                    $(".ratings").html(e); //REPLACES THE TEXT OF view.php
                }
            });
        }
    });


</script>
Sign up to request clarification or add additional context in comments.

Comments

0

If there's nothing else going on in this code, then remove the slashes from your onclick code. They are unnecessary and cause an error.

onclick="rate($(this).attr('id'))"

1 Comment

Or use the simpler this.id instead of $(this).attr('id').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.