Today, I sorted out the program code about uploading files and displaying the progress bar, and optimized the code. Solve the problem that has been plagued: Sometimes the progress bar does not reach 100%, and the browser is suspended. The tests in IE8 and chrome are perfect.
Project requirements:
Upload APK. the upload progress bar is displayed. After the upload is complete, start to analyze the APK. The apk data is being analyzed. Please wait.... After the analysis is complete, the APK data is uploaded successfully and uploaded again.
Since I installed winxp in English and IE in IE7 by default, I found that the progress bar was not displayed during the test. The percentage is not displayed.
Troubleshooting:
1. Change DOM to jquery mode and do not display
2. Add a delay to the recursive call without display. Add the latency code: setTimeout ("getProgress ('" + upid + "')", 500 );
3. Is it caused by a container level problem? Therefore, the module is tested whether to perform the upload process. Add a container on the page, write a global variable I, and write it to the container I ++ in the module called during the upload. The result is displayed, indicating that the container is called correctly.
4. If the progress bar and percentage are both 0, is there a problem with the received json data?
Because the returned code is echo json_encode ($ arr); It is json data, but to find out the cause, the returned data is executed once: var dataObj = eval ("(" + data + ")"); // convert to a json object
The script error is displayed.
5. Is it a cache? Therefore
Copy codeThe Code is as follows: $. getJSON ("ProcessBar. php", {progress_key: upid}, function (result ){
Changed:Copy codeThe Code is as follows: $. getJSON ("ProcessBar. php", {progress_key: upid, time :( new Date (). getTime ()}, function (result ){
Perfect solution.