Form ajax and ob_flush
Form ajax and ob_flush
我有这个形式:
<form id="monForm" action="indexer.php" method="post">
<input name="url" id="url" value="" class="url"/>
<input type="submit" id="envoyer" value="Parser" class="submit" />
</form>
<p id="infos"></p>
而这个Javascript:
<script>
$(document).ready(function(){
$('#monForm').submit(function() {
var url = $('#url').val();
$( "#result" ).empty();
// appel Ajax
$.ajax({
url: $(this).attr('action'), // le nom du fichier indiqué dans le formulaire
type: $(this).attr('method'), // la méthode indiquée dans le formulaire (get ou post)
data: $(this).serialize(), // je sérialise les données (voir plus loin), ici les $_POST
success: function(msg) { // je récupère la réponse du fichier PHP
$('#infos').append(msg+'%<br/>');
}
});
return false; // j'empêche le navigateur de soumettre lui-même le formulaire
});
});
我的索引器.php只是一段时间:
$i = 0;
while($i < 10){
echo $i."<br/>";
sleep(1);
$i++;
}
我不想在 1 次内返回数据(0、1、2、3 等)。
我认为我需要使用ob_flush但我不知道该怎么做。
请问有什么想法吗?
希望这对您有所帮助:
<?php
// start output buffer
if (ob_get_level() == 0) ob_start();
$i = 0;
while($i < 10){
echo $i."<br/>";
ob_flush();
flush();
sleep(1);
$i++;
}
?>
如果您尝试在打印数字之前引入延迟,我认为这段代码可能会有所帮助。
<?php
header( 'Content-type: text/html; charset=utf-8' );
$i = 0;
while($i < 10){
echo $i."<br/>";
if(sleep(1) != 0) {
echo 'sleep failed';
break;
}
flush();
ob_flush();
$i++;
}
?>
相关文章:
- AngularJS测试$resource-flush给出错误
- Angularjs $interval.flush()
- Jquery getScript 或 ajax 与 php flush 相结合
- 在试图将事件记录到flush中时,javascript中出现了非法字符语法错误
- 当服务抛出错误时,$httpBackend.flush失败
- AngularJS测试$httpBackend.flush()导致错误
- 错误:单元测试AngularJs服务时,没有待处理的flush请求
- 获取php flush的Javascript事件
- Angular资源测试:$httpBackend.flush()导致意外请求
- 我如何知道最后一个异步函数何时在ob" for键中返回结果?循环
- PHP电子邮件整个页面没有OB
- AngularJS:在$httpBackend.flush()之前需要$digest
- 来自Meteor的异常.flush: TypeError: Cannot read property 'pare