我有一個代碼,它增加了while
循環中的URL參數,直到$i
等於10.發生這種情況時,它將顯示每個數字最多10個(因爲這是$i
停止增加時) - 在這種情況下,它將是1,2,3,4,5,6,7,8,9。逐個顯示每個結果
問題是隻有當$i
等於10時它才顯示1,2,3 ,4,5,6,7,8,9 - 我需要它在發生時顯示數字(而不是等待$i
等於10!)。
<div id="here"></div>
<script>
$(document).ready(function(){
$.ajax({
type: "POST",
url: "test2.php",
success: function(data) { $("#here").html(data); }
});
});
</script>
test2.php:
while($content = file_get_contents('https://www.example.com?id='.$i)) {
if($i !== 10) {
echo $i;
}else{
break;
}
$i++;
}
腳本在瀏覽器中運行需要多長時間才能運行? – Akshay
@Akshay字面上只有幾秒鐘。然而,這是一個例子 - 我可以讓'$ i'高達10000,這需要一段時間。我也壓縮了代碼。 –
如果你的時間間隔是相同的,只需使用$ interval或$ timeout –