前端结合服务器实现进度条(待验证)-11

我现在实现了进度条是在后台方法实现完
才执行进度条方法
action代码
获得当前笔数
public void getCurrentCount(){
HttpSession session = getRequest().getSession();
String jsone=session.getAttribute("currentCount").toString();
System.out.println("*********************************************");
System.out.println(jsone+"当前笔数");
try {
getResponse().getWriter().println(jsone);
} catch (Exception e) {
e.printStackTrace();
}
}

实现代码
public void cert() throws InterruptedException {
CollPayDetail collPayDetail = new CollPayDetail();
collPayDetail.setMerchantId(merchantId);//305310083980003
collPayDetail.setBatchNo(batchNo);
collPayDetailList = collDao.selectCollPayList(collPayDetail);
HashMap<String, String> hashMap = new HashMap<String, String>();
try {
hashMap.put("code", "1");
String jsonStr = JSONObject.fromObject( hashMap).toString();
getResponse().getWriter().write(jsonStr);
getResponse().getWriter().flush();
getResponse().flushBuffer();
} catch (IOException e1) {
e1.printStackTrace();
}
Thread.sleep(5000);

if (collPayDetailList != null && collPayDetailList.size()!=0) {
for (int i = 0; i < collPayDetailList.size(); i++) {
getRequest().getSession().setAttribute("currentCount", i + 1);
CollPayDetail collPayDetai = collPayDetailList.get(i);
collService.toCert(collPayDetai);
}
}


页面


function realNameAuthClick(batchNo,batchCount){
if (!confirm("确认认证吗?")) {
             window.event.returnValue = false;
             return false;
        }else{
       
         var url = "<s:url value="/web.coll!cert.ac" />"
        document.getElementById("speed").style.display="block";
        var options = { 
    "type": "get",
    "url": url,
    "dataType":"json",
    // "async":true,
    "cache":false,
     "data":{"batchNo":batchNo,"merchantId":${sessionScope.managerBean.merchantId}},
    "beforeSend": function(XMLHttpRequest){
         $("#spaceused1").fadeIn();
         },
         "success": function(data, textStatus){
if(typeof(data) == 'string'){
alert(data);
return;
}
if(data){
if(data.error){
alert(data.error);
return;
}else if (data.code){
if(data.code == 1){
$.blockUI({message:"认证中……请稍候"});
 $("#spaceused1").progressBar(0, { showText: true, barImage: '<s:url value="/js/jquery.progressbar/images/progressbg_red.gif"/>'} );
//setTimeout(getProgress,5);
//getProgress();
setInterval(getProgress(),1000);
}
}
}else{
alert("未知错误");
$.unblockUI();
}
},
"error":function (XMLHttpRequest, textStatus, errorThrown) {
if(textStatus){
alert("服务器异常:  " + textStatus);
$.unblockUI();
}
else if (errorThrown){
alert("服务器异常:  " + errorThrown);
$.unblockUI();
}
          },

"complete":function(XMLHttpRequest, textStatus){
}
   };
   jQuery.ajax(options);
}

function getProgress(operName){
if( !operName )
operName = "操作";
var url = "<s:url value="/web.coll!getCurrentCount.ac" />"
var options = { 
    "type": "get",
    "url": url,
    "async":true,
    "dataType":"json",
    "cache":false,
    // "data":{"batchNo":batchNo,id:id},
    "beforeSend": function(XMLHttpRequest){
},
"success": function(data, textStatus){
try{
   var p = data/batchCount * 100;
  $("#spaceused1").progressBar(p, {width:190, showText: true, barImage: '<s:url value="/js/jquery.progressbar/images/05043110_1.gif"/>'} );
if(data < batchCount)
   setTimeout(getProgress,5);
  else{
    setTimeout('alert("' + operName + '完成");$.unblockUI();window.location.href = window.location.href;',1000);
  }
}catch(err)
{
     alert("js出错啦");
}
},
"complete":function(XMLHttpRequest, textStatus){
}
   };
   jQuery.ajax(options);
}
更多 0

你可能感兴趣的:(前端结合服务器实现进度条(待验证)-11)