怎么用DWR框架发出后缀名为.action的异步请求
展开全部
关键在DWR.XML里。
例子:
<?xml version="1.0" encoding="UTF-8"?>
<dwr>
<allow>
<create creator="spring" javascript="ubiz">
<param name="beanName" value="ubiz" />
<include method="findUser" /><!-- BIZ中的方法 -->
</create>
<convet match="com.entity.Users" converter="bean"/>
</allow>
</dwr>
页面接受
<script type='text/javascript' src='<%=basePath%>dwr/interface/ubiz.js'></script>
<script type='text/javascript' src='<%=basePath%>dwr/engine.js'></script>
<script type='text/javascript' src='<%=basePath%>dwr/util.js'></script>
function check_name(){
name_flag=0;
var username = document.forms[0].elements["users.uname"].value;
if(username == ''){
document.getElementById("usernameTip").className = 'alert';
document.getElementById("usernameTip").style.display = 'inline';
document.getElementById("usernameTip").innerHTML = '请输入用户名';
success=0;
return 0;
}
if(new RegExp("^[a-z_]{1,1}[a-z0-9_]{4,25}$").test(username) == false){
document.getElementById("usernameTip").className = 'alert';
document.getElementById("usernameTip").style.display = 'inline';
document.getElementById("usernameTip").innerHTML = '非数字开头,限5-26位小写字母、数字或下划线,请重新输入';
success=0;
return 0;
}
ubiz.findUser(username,result);
}
<!-- 回调函数 -->
function result(isExist){
bool = isExist;
var checkname=document.getElementById('usernameTip');
if(isExist){
checkname.innerHTML="<font color='#FF0000' size='-1'>*该用户名已被使用</font>";
}else{
checkname.innerHTML="<font color='#FF0000' size='-1'>^_^恭喜此用户名可用</font>";
}
}
调用:
<html:text property="users.uname" onblur="check_name()">
例子:
<?xml version="1.0" encoding="UTF-8"?>
<dwr>
<allow>
<create creator="spring" javascript="ubiz">
<param name="beanName" value="ubiz" />
<include method="findUser" /><!-- BIZ中的方法 -->
</create>
<convet match="com.entity.Users" converter="bean"/>
</allow>
</dwr>
页面接受
<script type='text/javascript' src='<%=basePath%>dwr/interface/ubiz.js'></script>
<script type='text/javascript' src='<%=basePath%>dwr/engine.js'></script>
<script type='text/javascript' src='<%=basePath%>dwr/util.js'></script>
function check_name(){
name_flag=0;
var username = document.forms[0].elements["users.uname"].value;
if(username == ''){
document.getElementById("usernameTip").className = 'alert';
document.getElementById("usernameTip").style.display = 'inline';
document.getElementById("usernameTip").innerHTML = '请输入用户名';
success=0;
return 0;
}
if(new RegExp("^[a-z_]{1,1}[a-z0-9_]{4,25}$").test(username) == false){
document.getElementById("usernameTip").className = 'alert';
document.getElementById("usernameTip").style.display = 'inline';
document.getElementById("usernameTip").innerHTML = '非数字开头,限5-26位小写字母、数字或下划线,请重新输入';
success=0;
return 0;
}
ubiz.findUser(username,result);
}
<!-- 回调函数 -->
function result(isExist){
bool = isExist;
var checkname=document.getElementById('usernameTip');
if(isExist){
checkname.innerHTML="<font color='#FF0000' size='-1'>*该用户名已被使用</font>";
}else{
checkname.innerHTML="<font color='#FF0000' size='-1'>^_^恭喜此用户名可用</font>";
}
}
调用:
<html:text property="users.uname" onblur="check_name()">
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询