我使用這個腳本重新加載一個DIV ID爲新聞,DIV的自動更新不工作
<script type="text/javascript">
var auto_refresh = setInterval(function() {
<? if ($lim >= 5)
$lim = 0;
else
$lim = $lim + 2;
if ($cnt == 1){
$lim = 0;
$cnt += 1;
} ?>
$('#news').load('update.php?lim=<? echo $lim ?>');
}, 10000); // refresh every 10000 milliseconds
</script>
的update.php containts此代碼接收LIM值,
$lim=$_GET['lim'];
但每過10秒後,'lim'值就會發送爲0.我需要根據腳本中的條件更新'lim'值。
我使用echo命令檢查update.php中的$ lim值。總是0.我的代碼中的錯誤是什麼?
PHP是服務器端,JavaScript是客戶端.... – ManseUK
javascript內的'php' setInterval()'! – thecodeparadox
您需要每次從服務器獲取'$ lim',例如使用AJAX調用。使用該值,因爲'$ lim'的第一個值在javascript中被硬編碼。 – Hidde