使用dwr回调函数为什么取不到值呢,在线等!!!
dwr.xml是这样配置的
<create creator="new" javascript="RoleManageService">
<param name="class" value="com.bcic.eros.web.rolemanage.service.RoleManageService"/>
</create>
service里面的方法在会执行到
public String getRoleInfo(String usrid) throws BizException{
String strReturn = "<tr><td>角色名</td><td>角色描述</td></tr>";;
if(!"".equals(usrid) && usrid != null){
RoleManageService rolemanageService = getRoleManageService();
String strBranch_No = rolemanageService.queryBranchNo(usrid);
List listRole = rolemanageService.queryRoleInfo(strBranch_No);
for(int i = 0; i < listRole.size();i++){
RoleManageDTO dto = (RoleManageDTO) listRole.get(i);
strReturn = strReturn + "<tr><td>" + dto.getRole_id() +"</td><td>" + dto.getDescription() + "</td></tr>";
}
}
strReturn = "<table id=role_table>" + strReturn + "</table>";
return strReturn;
}
页面是这样写的:
<script type='text/javascript' src='dwr/interface/RoleManageService.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<SCRIPT type="text/javascript" language="javascript">
RoleManageService.getRoleInfo('<%=userInfoDTO.getUserId()%>',even1);
var even1=function(data)
{
alert('aa');
var role_table = document.getElementById("role_table");
alert(role_table);
if( role_table != 'null' )
{
role_table.innerHTML = data;
}
}
</SCRIPT>
上面的RoleManageService.getRoleInfo能够正常执行,但在回调函数中就不能执行,也就是不会输出'aa'提示信息,这是为什么呢?在线等.
------解决方案--------------------路过学习,帮LZ顶~
------解决方案--------------------帮你顶 dwr 没有学过
------解决方案--------------------getRoleInfo方法确定被执行了喵?
------解决方案--------------------<script type='text/javascript' src='dwr/interface/RoleManageService.js'> </script>
<script type='text/javascript' src='dwr/engine.js'> </script>
<script type='text/javascript' src='dwr/util.js'> </script>
再加上一行
<script type='text/javascript' src='RoleManageService.js'></script>
试试看。
你在这个方法里面设置一个断点,debug下看可到这个方法里面去了
------解决方案--------------------var even1=function(data)
LZ这个是什么?
------解决方案--------------------
<SCRIPT type="text/javascript" language="javascript">
RoleManageService.getRoleInfo(' <%=userInfoDTO.getUserId()%>',even1);
function(event1){
var role_table = document.getElementById("role_table");
alert(role_table);
}
</SCRIPT>
LZ先试试把这个运行下看看
------解决方案--------------------
var even1=function(data) {
}
貌似你回调函数定义有问题啊!
用下面这个吧:
function even1(data){}
------解决方案-------------------- RoleManageService.getRoleInfo(' <%=userInfoDTO.getUserId()%>',function callback(data)