gpt4 book ai didi

javascript - 错误: Java Script code在哪里

转载 作者:行者123 更新时间:2023-12-01 02:31:50 25 4
gpt4 key购买 nike

应用程序基于 Yii2 构建,并使用 Kartik 的星级评分小部件。 js代码有错误:

控制台中出现错误的图像:

Uncaught SyntaxError: Unexpected token (

代码:

    <?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,
],

最佳答案

您忘记为 js 函数添加名称:

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);
}
});
}

关于javascript - 错误: Java Script code在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48259498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com