Ajax regularly updated automatically updated with the progress of the
Related Tags:
In a recent project, a 3.5 features: cvs upload a file, then write the file and analytical database as often require an enormous paper, customers often need to complete this function 40 minutes, in the process, Pages do not have any tips, the user experience is very good?
Why not make a progress of the ajax?
This needs to complete the two-step:
1: write a simple ajax and realizing the simple function of the progress.
Second: the progress of this transformation can be used for the progress of the project.
A: The most simple of progress
1. Client every two seconds createXMLHttpRequest sent a request to the server. Returned to the terminal to services and the progress of data. According to the service-return data, a table using javascript update the width,
This simulates a progress bar.
ProgressBar.html. Reads as follows:
<! DOCTYPE html PUBLIC "- / / w3c / / DTD HTML 4.01 Transitional / / EN">
<html>
<head>
<title> Ajax Progress Bar </ title>
<script Type="text/javascript">
Var xmlHttp;
Var key;
Function createXMLHttpRequest () (
If (window.ActiveXObject) (
XmlHttp = new ActiveXObject ( "Microsoft.XMLHTTP");
)
Else if (window.XMLHttpRequest) (
XmlHttp = new XMLHttpRequest ();
)
)
Function go () (
CreateXMLHttpRequest ();
ClearBar ();
Var url = "ProgressBarServlet? Create task =";
Var button = document.getElementById ( "go");
Button.disabled = true;
XmlHttp.open ( "GET", url, true);
XmlHttp.onreadystatechange = goCallback;
XmlHttp.send (null);
)
Function goCallback () (
If (xmlHttp.readyState == 4) (
If (xmlHttp.status == 200) (
SetTimeout ( "pollServer ()", 2000);
)
)
)
Function pollServer () (
CreateXMLHttpRequest ();
Var url = "ProgressBarServlet? Poll & task = key =" + key;
XmlHttp.open ( "GET", url, true);
XmlHttp.onreadystatechange = pollCallback;
XmlHttp.send (null);
)
Function pollCallback () (
If (xmlHttp.readyState == 4) (
If (xmlHttp.status == 200) (
Var percent_complete = xmlHttp.responseXML.getElementsByTagName ( "percent") [0]. FirstChild.data;
Var progress = document.getElementById ( "progress");
Var progressPersent = document.getElementById ( "progressPersent");
Progress.width percent_complete + = "%";
ProgressPersent.innerHTML percent_complete + = "%";
If (percent_complete <100) (
SetTimeout ( "pollServer ()", 2000);
Else ()
Document.getElementById ( "complete"). InnerHTML = "Complete!";
/ / Document.getElementById ( "go"). Disabled = false;
)
)
)
)
Function clearBar () (
Var progress_bar = document.getElementById ( "progressBar");
Var progressPersent = document.getElementById ( "progressPersent");
Var complete = document.getElementById ( "complete");
Progress_bar.style.visibility = "visible"
ProgressPersent.innerHTML = "";
Complete.innerHTML = "Begin to upload this file ...";
)
</ Script>
</ Head>
<body>
<div Id="progressBar" style="padding:0px;border:solid black 0px;visibility:hidden">
<table Width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td Align="center" id="progressPersent"> 86% </ td>
</ Tr>
<tr>
<td>
<table Width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#000000">
<tr>
<td>
<table Width="1%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FF0000" id="progress">
<tr>
<td> </ Td>
</ Tr>
</ Table> </ td>
</ Tr>
</ Table>
</ Td>
</ Tr>
<tr>
<td Align="center" id="complete"> completed </ td>
</ Tr>
</ Table>
</ Div>
<input id = "go" name="run" type="button" value="run" onClick="go();">
</ Body>
</ Html>
2: a simulated servlet: ProgressBarServlet1. Java, as follows:
Package com.cyberobject.lcl.ajax;
Import java.io. *;
Import javax.servlet .*;
Import javax.servlet.http .*;
/ **
*
* @ Author nate
* @ Version
* /
Public class ProgressBarServlet extends HttpServlet (
Private int counter = 1;
/ ** Handles the HTTP <code> GET </ code> method.
* @ Param request servlet request
* @ Param response servlet response
* /
Protected void doGet (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException (
String task = request.getParameter ( "task");
String res = "";
If (task.equals ( "create")) (
Res = "<key> 1 </ key>";
Counter = 1;
)
Else (
String percent = "";
Switch (counter) (
Case 1: percent = "10"; break;
Case 2: percent = "23"; break;
Case 3: percent = "35"; break;
Case 4: percent = "51"; break;
Case 5: percent = "64"; break;
Case 6: percent = "73"; break;
Case 7: percent = "89"; break;
Case 8: percent = "100"; break;
)
Counter + +;
Res = "<percent>" + + percent "</ percent>";
)
PrintWriter out = response.getWriter ();
Response.setContentType ( "text / xml");
Response.setHeader ( "Cache-Control", "no-cache");
Out.println ( "<response>");
Out.println (res);
Out.println ( "</ response>");
Out.close ();
)
/ ** Handles the HTTP <code> POST </ code> method.
* @ Param request servlet request
* @ Param response servlet response
* /
Protected void doPost (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException (
DoGet (request, response);
)
/ ** Returns a short description of the servlet.
* /
Public String getServletInfo () (
Return "Short description";
)
)
3: In the web. Xml configuration in good servlet mapping:
<! - Action Servlet Mapping ->
<servlet>
<servlet-name> ProgressBarServlet </ servlet-name>
<display-name> ProgressBarServlet </ display-name>
<servlet-class> Com.cyberobject.lcl.ajax.ProgressBarServlet </ servlet-class>
</ Servlet>
<servlet-mapping>
<servlet-name> ProgressBarServlet </ servlet-name>
<url-pattern> / ProgressBarServlet </ url-pattern>
</ Servlet-mapping>
At this time of the progress already running. The next work is to transplant it to our system.
2:
1: writing class DbOperater database, add a progress attribute
Private int progress;
2: writing database class, add a getProgress () method:
Public int getProgress ()
(
Return progress;
)
3: the writing for the cycle, progress + +;
4: Calling the servlet DbOperater Calling DbOperater the getProgress () method, such as on the progress of the provision of real-time data.
5: Also: servlet the doGet () to access the progress of data, doPost () to upload files and the write operation. Clear division of work and each other.
Hereby filing.
- Contribute 3 with easily updated, publishing page graphic
- Ajax regularly updated automatically updated with the progress of the
- FlashAS Guide: In the main film production outside of the loading progress
- Action Applications: getURL framework can be updated
- A simple, easy-to-use progress
- Pai recommended: ALEXA ranking automatically updated with tips
- The realization of a non-ajax based on the updated version of the Simple Chat
- AJAX File upload Progress
- How to submit to the Alexa Web site, including updated picture
- Ajax progress of the
- Dreamweaver MX 2004 to Information Notice (7) management page notice of the updated page production
- Ajax progress of the JSP +
- Ajax regularly updated automatically updated with the progress of the
- Factors affecting website updated
- Javascript realization of a set with updated data
- A loading pages of progress
- Background music can be automatically updated each time change
- Div CSS JS tree menu can be updated
- In the main film production progress of the external load
- [To] use dwr + ajax struts development and progress of the file upload
- Update site updated google impact factors
- JavaScript can be automatically updated pages
- Alexa rankings updated study data
- Drag the progress of the player production
- Jump or not updated website to achieve regional selection show
- Flash progress of the super-simple production skills
- On page designer color: simple, clean, and progress
- Ajax - file upload progress of the state.
- AJAX Based on the WEB file upload control the progress of
- Ajax achieve Shuabing not achieved under the precondition of pages regularly updated
- Using Dreamweaver document library website updated
- Flash Player drag the progress of the production
- Flash skills: judgement external videos included in the progress of the two methods
- Javascript father used to achieve the updated form
- Uploadsample (upload files and upload Ajax showed progress)
- WEB2.0 standard 12-day course of gradual and orderly progress based learning!




