Hi, sorry for my english, I need help with a script please.
I have a star rating script on my website, that work fine on firefox and safari but but on IE.
My html:
<script type="text/javascript" src="loco/rate-product-ajax.js"></script>
<form>
<input class="star rate" type="radio" name="rate" value="1" />
<input class="star rate" type="radio" name="rate" value="2" />
<input class="star rate" type="radio" name="rate" value="3" />
<input class="star rate" type="radio" name="rate" value="4" />
<input class="star rate" type="radio" name="rate" value="5" />
</form>
I call two files:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="loco/jquery.rating.js"></script>
rate-product-ajax.js
$(document).ready(function() {
var some_product_id=77;
//let's say it's product with id=1, if you have application you will change this variable programatically
getRating(some_product_id);
function getRating(id){
$.ajax({
type: "GET",
url: "loco/rate-product.php",
dataType : 'json',
processData: false,
data: "do=getRate&product_id=" + id,
cache: false,
async: false,
success: function(result) {
avg=result.avg;
sum=result.count;
$("#votes").html;
$(".vote_count").html(sum + " vote(s)");
$('.rate').rating('select',avg);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus+' - '+errorThrown);
}
});
}
$('.rate').click(function(){
$.ajax({
type: "GET",
url: "loco/rate-product.php",
dataType : 'json',
data: "do=rate&product_id=" + some_product_id + "&rate="+$(this).text(),
cache: false,
async: false,
success: function(result) {
avg=result.avg;
sum=result.count;
$("#votes").html("Average:" + avg);
$(".vote_count").html(sum + " vote(s)");
$('.rate').rating('select',avg);
$('input',this.form).rating('readOnly',true);
//$('input',this.form).rating('disabled',true);
//$('input',this.form).rating('return',false);
$('.rate').unbind('click');
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus+' - '+errorThrown);
}
});
});
});
My php file
function getRate() {
$sql= "select ifnull(round(sum(rate)/count(*),0),0) avg, count(*) count from rate where product_id=" . $_GET['product_id'];
if($result=mysql_query($sql)) {
if($row=mysql_fetch_array($result)) {
$rate['avg'] = $row['avg'];
$rate['count'] = $row['count'];
echo json_encode($rate);
}
}
}
/* $ip = $_SERVER["REMOTE_ADDR"];
$product = $_GET['product_id'];
$valideip = "SELECT * FROM rate WHERE ip = '$ip' AND product_id = '$product' ";
$row_ip = mysql_num_rows($valideip);
if($row_ip < 1)
*/
// function to insert rating
function rate() {
$ip = $_SERVER["REMOTE_ADDR"];
$product = $_GET['product_id'];
$valideip = "SELECT * FROM rate WHERE ip = '$ip' AND product_id = '$product' ";
$sql = "insert into rate (product_id, rate, ip) values (" . $_GET['product_id'] . ", ".$_GET['rate'].",'$ip')";
if($result=mysql_query($sql)) {
getRate(); //call retrieve from getRate function
}
}
if(!empty($_GET['do'])) {
include 'config.php';
include 'opendb.php'; //open database connection
if($_GET['do']=='rate'){
// do rate
rate();
}
else if($_GET['do']=='getRate'){
// get rating
getRate();
}
}
On Internet explorer an error appear: parsererror undefined I don’t know if the script can open rate-product.php.