我也是mootools和web开发的新手。我读过这篇很酷的blog 并且我想扩展代码以连接数据库以使用php文件更新评级。但不幸的是我的代码不工作意味着数据库没有更新。有人可以解释一下为什么。非常感谢...
这是代码
star.html
<html>
<script src="mootools-1.3.js"></script>
<script src="lorenzos-MooStarRating-422072a/Source/moostarrating.js"></script>
<script>
// Configure the image paths
var MooStarRatingImages = {
defaultImageFolder: 'lorenzos-MooStarRating-422072a/Graphics/',
defaultImageEmpty: 'star_empty.png',
defaultImageFull: 'star_full.png',
defaultImageHover: "star_boxed_hover.png"
};
// Post iD
var postId = 10;
// When the DOM is ready....
window.addEvent("domready",function() {
// Create our instance
// Advanced options
var advancedRating = new MooStarRating({
form: 'ratingsForm',
radios: 'rating',
half: false,
//imageEmpty: 'star_boxed_empty.png',
//imageFull: 'star_boxed_full.png',
//imageHover: "star_boxed_hover.png",
width: 17,
tip: 'Rate <i>[VALUE] / 7.0</i>',
tipTarget: $('htmlTip'),
tipTargetType: 'html',
click: function(value) {
// Send ajax request to server
new Request.send({
url: "rateSave.php",
data: {'rating': value}
});
}
});
});
</script>
<form name="ratingsForm">
<label>Select The Number of Stars</label>
<input type="radio" name="rating" value="1.0" checked="checked">
<input type="radio" name="rating" value="2.0">
<input type="radio" name="rating" value="3.0">
<input type="radio" name="rating" value="4.0">
<input type="radio" name="rating" value="5.0">
<input type="radio" name="rating" value="6.0">
<input type="radio" name="rating" value="7.0">
<!--<input type="radio" name="rating" value="7.5">
<input type="radio" name="rating" value="8.0">
<input type="radio" name="rating" value="8.5">
<input type="radio" name="rating" value="9.0">
<input type="radio" name="rating" value="9.5">
<input type="radio" name="rating" value="10.0">-->
<span id="htmlTip"></span>
</form>
</html>
rateSave.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rating", $con);
$starCount =$_POST['rating'];
$result=mysql_query("INSERT INTO star VALUES('hotel','$starCount')");
mysql_close($con);
?>
答案 0 :(得分:6)
嗨Pavithra Gunasekara,错误是'没有',这里:
click: function(value) {
// Send ajax request to server ...
}
而不是'click',CallBack函数的名称是onClick,即
onClick: function(value) {
// Send ajax request to server ...
}
关于'点击',你可以这样做,即
advancedRating.addEvent('click', function(){ new Request.send({/* ... */}) });
使用'onClick'而不是新实例定义中的'click'的工作示例:http://jsfiddle.net/steweb/LDw4y/