前端結合服務器實現進度條(待驗證)-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();
}
}jquery

實現代碼
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);web

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);
}
}ajax


頁面json


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);
}session

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);
}
更多 0async

相關文章
相關標籤/搜索