81,092
社区成员
发帖
与我相关
我的任务
分享
<h2>文件上传显示进度</h2>
<iframe id='target_upload' name='target_upload' src='' style='display: none'></iframe>
<form id="form3" method="POST" enctype="multipart/form-data" action="AJAXFileUploadServlet" target="target_upload">
<input type="file" name="myFile"/><br/>
<input type="button" value="提交" id="myButton"/><br/>
</form>
<div id="show"></div>
<script type="text/javascript">
$(function(){
$("#myButton").click(function(){
$("#show").html("");
$(this).attr("disabled",true);
$("#form3").submit();
setTimeout("showProgress()",500);
});
});
function showProgress(){
$.getJSON("SeeProgressServlet",function(json){
$("#show").html("上传进度:"+(json.PBytesRead/json.PContentLength)*100+"%");
if(json.PBytesRead == json.PContentLength){
$("#show").html($("#show").html()+"上传结束~");
$("#myButton").attr("disabled",false);
}else{
setTimeout("showProgress()",500);
}
});
}
</script>
利用ifram单独刷新form的页面上传实例