我调用flush但页面只挂了5秒(故意)然后完全呈现。为什么它不显示我的第一部分然后是最后一部分?
Firefox 7和Chrome都这样做
代码文件
using System;
namespace ABC
{
public class Test
{
static public void Apple()
{
System.Web.HttpContext.Current.Response.Flush();
System.Threading.Thread.Sleep(5000);
}
}
}
页
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
hi
<form id="form1" runat="server">
<div>
starting
<% ABC.Test.Apple(); %>
<% WebApplication1._Default.RecurseMe(Response, @"/var/www/wordpress", 0); %>
</div>
</form>
</body>
</html>
答案 0 :(得分:2)
我认为网页浏览器在加载HTML之前不会显示该页面。以这种方式考虑..有些标签需要在页面正确呈现之前关闭并且是标签。
我不确定你为什么需要这样做,但如果你想在加载时隐藏一些数据,你应该隐藏隐藏div中的区域,然后在时间间隔之后使用javascript或其他一些方法显示它。作为AJAX回调。