0

单击时没有运行的任何原因?我似乎无法弄清楚。

<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>
4

2 回答 2

1

干得好:

<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>
于 2013-11-05T23:29:09.397 回答
0

如果此代码中没有其他内容,请从onclick代码中删除斜杠。它们是不必要的并且会导致错误。

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

于 2013-11-05T23:28:18.620 回答