我写的这个 jquery 代码有问题:
$('.star').click(function(){
$('#errors').removeClass().html('');
var term = $(this).id;
var posting = $.get("aj_vote_opere.php", { rating: term, opera: '<?php echo $_GET['id']; ?>' },
function(data) {
$('#errors').addClass(data.stileError).html(data.message);
}, "json");
}
我的 HTML 代码如下所示:
<div class="rating">
<span id="5" class="star">☆</span><span id="4" class="star">☆</span><span id="3" class="star">☆</span><span id="2" class="star">☆</span><span id="1" class="star">☆</span>
</div>
<div id="errors"></div>
在 php 文件中,我想将投票存储在数据库中。似乎没有发送 GET var。我想是因为我没有要提交的表格。我以前使用过 $.post 但我意识到没有表格 = 没有帖子。但是 $.get 呢?我真的很感激任何提示。提前致谢。
编辑
这是我的 aj_vore_opere.php:
<?php
include('Connections/dbConn.php');
if(!isset($_SESSION['u_id']))
{
$voto_q = "INSERT INTO ar_opere_rating (rate,opera) VALUES ('".$_GET['rating']."','".$_GET['id']."')";
$voto_x = fln_query($voto_q);
$msg = $voto_q.'Il tuo voto è stato correttamente registrato.';
$bgClass = ' ok';
}
else
{
$msg = 'Attenzione, devi essere registrato per votare. Vuoi registrarti? <a href="reg.php">Clicca qui</a>';
$bgClass = ' ko';
}
echo json_encode(
array(
'message'=>$msg,
'stileError'=>$bgClass
)
);
?>