这是一个星级评级系统,我试图通过用户发送,包括对产品的评论和从20 =1星,40 =2星,等等…无论用户提交哪个星,它只取第一个值(100 =5星),下面是代码:
<input id="star5" name="star" type="radio" value="100" class="radio-btn hide" />
<label for="star5">☆</label>
<input id="star4" name="star" type="radio" value="80"
class="radio-btn hide" />
<label for="star4">☆</label>
<input id="star3" name="star" type="radio" value="60"
class="radio-btn hide" />
<label for="star3">☆</label>
<input id="star2" name="star" type="radio" value="40"
class="radio-btn hide" />
<label for="star2">☆</label>
<input id="star1" name="star" type="radio" value="20"
class="radio-btn hide" />
<label for="star1">☆</label>
<button type="submit" class="btn btn-block btn-main" id="commentbtn" onclick="comment()" > Send </button>
下面是ajax代码:
function comment() {
var comment = $('#comment').val();
var star = $('input[name=star]').val();
var product_id = '<?php echo $productID;?>';
var username = '<?php echo $_SESSION["username"];?>';
jQuery.ajax({
url: "comment.php",
data: {
comment: comment,
product_id: product_id,
star: star,
username: username
},
type: "POST",
success: function(data) {
swal({
text: "comment has been submitted",
icon: "success",
button: false,
timer: 1500,
});
$(document).ready(function(e) {
setTimeout(function() {
window.location.href = "single.php?product_id=" + product_id
}, 1500)
});
},
error: function() {}
});
}
转载请注明出处:http://www.jxbyjx.net/article/20230526/1710724.html