很抱歉重复的问题,但给定的答案对我不起作用。
到目前为止,我使用Ajax在单击按钮后执行PHP,并使用ob_flush()逐个清除echo()。然而,我看到我的回声即将到来。以下是我的代码:
PHP:
$('#main-navigation li').each(function () { //<---correct id selector
var currLink = $(this);
var refElement = $(currLink.find('a').attr("href")); //<---find the anchor here
if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
$('#main-navigation ul li').removeClass("active"); //<---and here
currLink.addClass("active");
}
else{
currLink.removeClass("active");
}
});
AJAX:
ob_start();
echo "Server received this information from user: ". $debugMode. "<br>";
echo "Server answers this: <br>";
ob_flush();
for ($i = 1; $i <= 10; $i++)
{
echo( "Hello World ". $i. "<br>" );
ob_flush();
usleep(200000); //wait 0.2 seconds
}
ob_end_flush();
?>
感谢您的帮助! 彼得
答案 0 :(得分:0)
http://php.net/manual/kr/function.ob-implicit-flush.php
implicit-flush会帮助你。
并且,您将'xmlhttp.readyState == 4'修改为'xmlhttp.readyState == 3'