The principle is very simple, that is, when a certain operation may take a long time, you can have a prompt in the browser
The progress bar is actually a simple digital display.
Start of Construction ~~~~~~~~~~~~~
Several pages are easy to write and can be implemented ,:-)
Three pages:
P.htm: displays the current server progress Static Page and submits the Ajax page.
P. aspx server operation page, time-consuming page
P1.aspx: Obtain the current (P. aspx) completed progress result page
P.htm
JS:
<Script language = "JavaScript" type = "text/JavaScript">
VaR _ n = 0;
VaR XMLHTTP;
Function getpercent (){
If (_ n = 0 ){
If (window. activexobject) {XMLHTTP = new activexobject ("Microsoft. XMLHTTP");} else {XMLHTTP = new XMLHttpRequest ();}
_ Url = "P. aspx? Time = "+ new date ();
XMLHTTP. Open ("get", _ URL, true );
XMLHTTP. Send (null );
}
If (window. activexobject) {XMLHTTP = new activexobject ("Microsoft. XMLHTTP");} else {XMLHTTP = new XMLHttpRequest ();}
_ Url = "p1.aspx? Time = "+ new date ();
XMLHTTP. onreadystatechange = getcomplete;
XMLHTTP. Open ("get", _ URL, true );
XMLHTTP. Send (null );
}
Function getcomplete (){
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200 ){
_ P = parseint (XMLHTTP. responsetext );
If (_ p <= _ n) return;
Else {
_ N = _ P;
Document. getelementbyid ("spanp"). innerhtml = + _ N;
}
}
}
Function Init (){
If (_ n <50 ){
Getpercent ()
SetTimeout ("Init ()", 500 );
}
}
</SCRIPT>
HTML:
<Body onload = "Init ();">
<Div> completed: <span id = "spanp"> </span> </div>
</Body>
P. aspx:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "P. aspx. cs" inherits = "productmanage_p" %>
P. aspx. CS:
Protected void page_load (Object sender, eventargs E)
{
Session ["num"] = 0;
This. dosomething ();
}
Protected void dosomething ()
{
System. Threading. thread t = new system. Threading. Thread (new system. Threading. threadstart (threadproc ));
T. Start ();
}
Public void threadproc ()
{
For (INT I = 0; I <= 50; I ++)
{
Session ["num"] = I;
System. Threading. thread. Sleep (500 );
}
}
// A thread is used to assign a value to the session ["num"]. The value can be changed as needed in actual use.
P1.aspx:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "p1.aspx. cs" inherits = "productmanage_p1" %>
P1.aspx. CS
Protected void page_load (Object sender, eventargs E)
{
Response. Write (session ["num"]. tostring ());
}
It seems that the previous requirements can be met, although it is really ugly
Close !!!!!