0

Aplication is built on Yii2 with using Kartik's star-rating widget. Js code have an error:

Image with error in console:

Uncaught SyntaxError: Unexpected token (

Code:

    <?php 
    $js = <<<JS
                            function (event, value, caption) { 
                                $.ajax({
                                    type: 'GET', 
                                    url: '/rating/update-rating', 
                                    data: { 
                                        points: value, 
                                        post_id: $post->id
                                    }, 
                                    success: function(res) { 
                                        $(event.currentTarget).rating('update', res); 
                                    }, 
                                    error: function(e) {  
                                        console.log(e); 
                                    }  
                                }); 
                            }
    JS;
    $this->registerJs($js);

echo StarRating::widget([
                        'name' => $post->post_rate,
                        'value' => isset($post->rating[0]['dec_avg']) ? $post->rating[0]['dec_avg'] : 0,
                        'pluginOptions' => [ ... ] 
                            'pluginEvents' => [
                                'rating:change' => $js,
                            ],

1 Answer 1

2

You forgot to add a name for your js function:

function functionName(event, value, caption) {
    $.ajax({
        type: 'GET',
        url: '/rating/update-rating',
        data: {
            points: value,
            post_id: $post - > id
        },
        success: function(res) {
            $(event.currentTarget).rating('update', res);
        },
        error: function(e) {
            console.log(e);
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

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.