我想用ajax刷新div但是当我从mysql中选择项目时它不会刷新页面。这是我的代码
INDEX.PHP页面
<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#divToRefresh').load('cart.php');
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
</script>
<div id="divToRefresh"></div>
这是CART.PHP页面
<?php
include "admin/konet.php";
$itemsTotal = mysql_query("select sum(quantity) as `quantity` from `products_added` where `username` = '".mysql_real_escape_string($_SESSION["REMOTE_ADDR"])."'");
$get_itemsTotal = mysql_fetch_array($itemsTotal);
$items = ($get_itemsTotal["quantity"]); //Get total of all product
echo '<font id="cat">'.$items.'</font>';
?>
答案 0 :(得分:1)