I'm currently working with an e-commerce shopping site where different products require to be rated. I'm using a star rating script.
Everything is working fine but a product should be rated only once according to the visitor's IP and once the visitor clicks a star (among the five stars), all the stars should be disabled so that duplicate rating for the same product with the same IP can be prevented (I'm also using serve side validations) and average rating according to the new value from the database should be indicated by the same stars (which have just been disabled).
It's working on Firefox with no problem at all. When a visitor clicks a star a new value is passed to the database (using Ajax) and according to the new value, average rating is calculated and displayed but Internet explorer is unable to retrieve the new value from the database using Ajax.
I'm just demonstrating the problem with very simple code as follows.
Following is Temp.php file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
var xmlhttp;
function ajax()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp = new ActivexObject("Microsoft.XMLHTTP");
}
}
function loadStars(prod_id)
{
ajax();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("ajax_response").innerHTML=xmlhttp.responseText;
var rating= document.getElementById("rating_value").value;
alert(rating); //Rating value of hidden field from the ajax response is alered.
}
}
var queryString="Temp1.php?prod_id="+prod_id;
xmlhttp.open("GET", queryString, true);
xmlhttp.send();
}
</script>
</head>
<body onload="loadStars(11);">
<span id="ajax_response"></span>
</body>
</html>
and the following is the Temp1.php
<?php
include_once("../Connection.php");
$con=new Connection();
$con->get_connection();
if(isset($_GET['prod_id']))
{
$result=mysql_query("select rating_num from rating where prod_id=".$_GET['prod_id']."");
$rating=mysql_result($result, 'rating_num');
echo "<input type='hidden' id='rating_value' name='rating_value' value='$rating'/>";
}
?>
The code in both the files has nothing to do with. The js function loadStars(prod_id)
is called on the onload
event (look at the body tag) which actually invokes the Ajax request to the Temp1.php
which retrieves rating_num
from the database and simply stores into a hidden field named rating_value
which is finally alerted on the Temp.php
file using alert(rating);
The actual question is here when the value of rating_num
is changed in the database, Firefox displayed the updated value which is essential BUT Internet explorer (8) still displays the old value even though the page is refreshed and reload again and again.
What should be the reason? Is there any solution to this problem? Hope you will be able to understand what I mean.