利用 ASP 內建緩衝機制,通過 `Response.Flush` 分批輸出 HTML 片段,在長時間後台處理過程中即時向瀏覽器推送進度更新,實現無組件的服務端進度條效果。
`)並 `Response.Flush` 立即推送給瀏覽器。response.buffer = true
dim lostnum, shownum
delayshow(dstep, dmax)
sub delayshow(dstep, dmax)
dim total, dtemp
total = 100
dtemp = dstep
dstep = dstep + lostnum
if (dstep * total) / dmax < 1 then
lostnum = lostnum + dtemp
else
for ccc = 1 to fix((dstep * total) / dmax)
Response.Flush
shownum = shownum + fix((dstep * total) / dmax)
lostnum = 0
next
end if
end sub
sub showlost()
for ccc = 1 to (100 - shownum)
Response.Write("<img src='bar.gif'>")
next
Response.Write "<br>"
Response.Flush
end sub
註:更多精彩教程請關注三聯圖文教程頻道。