DWR同步和异步设置

jsp页面引入dwr相应文件:

 

<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%  >/dwr/interface/aaaService.js"></script>

 

    DWR设置同步:DWREngine.setAsync(false);

   

    DWR设置异步:DWREngine.setAsync(true);   其中async 是异步的意思。

 

    DWR默认是异步,所以当需要设置DWR同步时,只需DWREngine.setAsync(false);  但是当处理完成之后需要将DWR设置回默认的异步状态,所以需再加上DWREngine.setAsync(true); 

 

代码示例:

 

function getCity() {
     var province = theForm.elements("province").value;
 
     DWREngine.setAsync(false);
     aaaService.queryCityList(province , {callback:function(data){
          DWRUtil.removeAllOptions("city");
          DWRUtil.addOptions("city", [{dm:"", mc:"---请选择---"}], "dm", "mc");
         DWRUtil.addOptions("city", data, "value", "label");
     }});
     DWREngine.setAsync(true);
 
     var city = theForm.elements("city").value;
     getTown(city);
}

 

你可能感兴趣的:(JavaScript,jsp,DWR)