【发布时间】:2012-05-06 06:52:47
【问题描述】:
我目前正在与需要对不同产品进行评级的电子商务购物网站合作。我正在使用星级评分脚本。
一切正常,但是根据访问者的 IP,一个产品应该只被评分一次,一旦访问者点击一个星(五颗星中),所有星应该被禁用,这样同一产品的重复评级与可以防止相同的 IP(我也在使用服务端验证),并且根据来自数据库的新值的平均评分应由相同的星号指示(刚刚被禁用)。
它在 Firefox 上运行完全没有问题。当访问者点击星号时,一个新值会被传递到数据库(使用 Ajax),并根据新值计算并显示平均评分,但 Internet Explorer 无法使用 Ajax 从数据库中检索新值。
我只是用非常简单的代码来演示问题,如下所示。
下面是 Temp.php 文件
<!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>
以下是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'/>";
}
?>
这两个文件中的代码都与此无关。 js函数loadStars(prod_id)在onload事件上被调用(查看body标签),它实际上调用了对Temp1.php的Ajax请求,从数据库中检索rating_num并简单地存储到一个名为@987654327的隐藏字段中@ 最终在 Temp.php 文件上使用 alert(rating); 发出警报
真正的问题是当rating_num 的值在数据库中发生变化时,Firefox 显示更新后的值,这是必不可少的,但 Internet Explorer (8) 仍然显示旧值,即使页面被刷新并一次又一次地重新加载。
应该是什么原因?这个问题有什么解决办法吗?希望你能明白我的意思。
【问题讨论】:
标签: php javascript ajax