-1
我正在使用ajax & php構建星級評分系統。當用戶點擊時,不僅需要發送'星號'值,還需要發送被評價項目的標識符。我怎樣才能發送?我目前正在嘗試回顯ID#。同時,我試圖使用PHP實時顯示SQL表中的當前評級。我應該以另一種方式做這件事嗎?json傳遞兩個參數
形式單選按鈕
<div class="rating">
<form name="star" class="rating" method="post" action="getStarno(this.value, <?php echo $id; ?>)"
<legend><?php if(is_null($avgrate)){echo "Rate me!";} else {echo round($avgrate, 2);} ?>/3</legend>
<fieldset>
<input type="radio" name="Starno" value="1" onclick="this.form.submit()"/>
<input type="radio" name="Starno" value="2" onclick="this.form.submit()"/>
<input type="radio" name="Starno" value="3" onclick="this.form.submit()"/>
</fieldset>
</form>
</div>
JS
function getStarno(int, $id)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rating").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../rating.php?Starno="+int,true);
xmlhttp.send();
}
PHP
<?php
isset($_GET['id']);
isset($_GET['starno']);
$con=mysqli_connect ("","","","");
mysqli_query($con,"INSERT INTO ratings (storyidr, rank, entry_date)
VALUES ('$_GET[id]','$_POST[starno]',now())");
mysqli_close($con);
?>
[調用兩個js函數並不打印消息]的可能重複(http://stackoverflow.com/questions/13406753/calling-two-js-functions-and-dont-print-message) – rhill45