当前位置: 代码迷 >> J2SE >> dwr中有关js函数的一个简单有关问题
  详细解决方案

dwr中有关js函数的一个简单有关问题

热度:28   发布时间:2016-04-24 12:14:53.0
dwr中有关js函数的一个简单问题。
对于DWR不是太熟,所以有点问题。 请帮我找找问题所在吧。 先谢了。

在js中函数
<script language="javascript1.2">
var vote_siteId = "012332323232";
function Vote_doVote(voteId) {
var arr = document.getElementsByName(voteId);
var selectId = "";
for (var i = 0; i < arr.length; i ++) {
if (arr[i].checked) {
selectId = arr[i].getAttribute("id");
}
}
if (selectId == "") {
alert("请选择一项信息");
return;
}
callMethod(function(str){
if (str == "true") {
alert("投票成功");
} else {
alert("投票失败,同一ip只能投一票!");
}
},"org.plugin.vote.action.VoteAction.doVote",vote_siteId,voteId,selectId);
}
</script>
在html页面提交时,总是提示“callMethod(function(str){.........}函数中缺少对象“

其中org.plugin.vote.action.VoteAction.doVote函数。如下:
  public String doVote(HttpServletRequest request, String siteId, String voteId, String selectId)
  {
  String userIp = request.getRemoteAddr();
  if (this.voteRuleService.getVoted(voteId).size() > 0) {
  return "false";
  }
................
}

------解决方案--------------------
不懂啊,帮顶。祝楼主好运
------解决方案--------------------
没有看懂你的callMethod(function(str){是个什么东西?
我有一个Dwr练习列子,分享给你,希望对你有用
代码如下:
JSP代码
HTML code
<%@ page language="java" contentType="text/html; charset=GBK" %><% String path = request.getContextPath(); %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=GBK">      <title>First DWR</title>    <script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>      <script type="text/javascript" src="<%=path%>/dwr/util.js"></script>        <script type="text/javascript" src="<%=path%>/dwr/interface/Hello.js"></script>        <script language="javascript">        function hello() {                var userValue = dwr.util.getValue("user");            //获取参数方法1                          alert("使用Dwr框架取得Html 参数的值>"+userValue);                          Hello.hello(userValue,ccc);//这里的hello是Hello类中的方法                          alert("使用Dwr框架取得Html 参数的值>"+userValue);        }                //ccc回调方法Date返回的数据        function ccc(data){                     alert("Hello. hello 返回值"+data);                     alert("Dwr 框架 重新构建HTML web"+data);                     dwr.util.setValue("responseDiv",data);        }        </script></head><body>     <input id="user" name="user222" type="text" value="ddd" />     <input type="button" value="HELLO" onclick="hello();" />      <hr/>    <div id="responseDiv"></div> </body></html>
  相关解决方案