Ajax 的发送请求和直接提交Form 到Action 有什么区别?

项目的说明,我是用jxl 生成excel 报表但是由于生成的报表过程涉及到大量的计算,客户等待时间较长。所以客户需要一个类似于进度条的东西,或者一句提示的信息让客户知道 现在正在生成Excel 请等待。。。

等到生成玩了之后,应提示用户生成完成!!

可是我用JavaScript 请求 action 可以。但是用Ajax 提交请求就不可以!请问为什么??

/*
*javascript 的提交到Action
*/

<script>
function ms(){
document.location.href="<%=imgpath%>/yusuan/tongji/titletongji.do?yearStr="+yearStr;
    }
</script>

/*
*Ajax 的提交Action
*/
<script>
    var xmlhttp;
                       
                        try{
                                  xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
                    
                         }catch(e){
                                    try{
                                            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
                                    }catch(e){
                                                    try{
                                                             xmlhttp= new XMLHttpRequest();
                                                     }catch(e){ }
                                    }
                        }
            

                     
        xmlhttp.onreadystatechange = function(){
                       if(xmlhttp.readystate==4){
                                  if(xmlhttp.status==200){
                                   parseResults();   
                                              }else{
                                                     var ref=document.getElementById("menu1");
ref.style.visibility="visible";
                                              }
                                 }else{
                                 var ref=document.getElementById("menu1");
ref.style.visibility="visible";
                                 }
}
                      
        function parseResults(){
    if(xmlhttp.responseText.substring(0,5)=="wrong"){    
    var ref=document.getElementById("menu1");
ref.style.visibility="hidden";
    //return;
    }
    }
  
function ms(){

var yearStr = document.getElementById("yearStr").value;
var ref=document.getElementById("menu1");
ref.style.visibility="visible";
xmlhttp.open("post","<%=imgpath%>/yusuan/tongji/titletongji.do?yearStr="+yearStr);
            xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//            xmlhttp.setRequestHeader('Content-Disposition','attachment;filename=' + "sdf" + '.xls', 'utf-8');
                xmlhttp.send(null);
                return ;
}
                      
          
          // }          
       
</script>


你可能感兴趣的:(JavaScript,Ajax,Excel,Microsoft)