更新页面时进行ajax调用
I have an ajax call to one php script via jquery but it takes a lot of time to return results , So I would like to know how can I display results as its are being printed on my script. here just example of my php script:
<?php
// process.php
for($i = 0; $i <= 4; $i++){
echo json_encode(array("name" => $i) );
sleep(2); // this sleeps for 2 seconds
}
?>
Now with my jquery i am calling that page and have a form with id ajaxquery on page:
$("#ajaxquery").live( "submit" , function(){
var formdata = $(this).serialize();
$.ajax
({
type: "POST",
url: "process.php",
data: formdata,
dataType: "json",
success: function(data)
{
$("#success").html(data.name);
}
});
return false;
});
now this will output all results at same time after few seconds in div#success but how can i achieve it print that echo statements as soon process.php process it and then again wait 2 seconds and add next result in div success. thanks for any help.
weixin_33729196
2011/12/01 11:19- ajax
- jquery
- 点赞
- 收藏
- 回答
2个回复
