iframe里的页面跳转不行?

hooligan00011 2012-12-11 09:43:53
在做简单的考试系统时碰到的问题:
我在会话里存入生成的考试题目,按“下一题”显示一道题目
JSP里用btclick事件用jquery:

$("#btNext").click(function(){
answer = $("input[name='answerId']:checked").val();
pos = $("input[name='pos']").val();
utid = $("input[name='utid']").val();
alert("pos: "+pos+" utid: "+utid);
if(null == answer || "undefined" == answer){
alert("请选择题目,不能为空!");
return ;
}else{
$.ajax({
type: 'POST',
url: 'updateUT.do',
data: {'pos':Number(pos+1),'act':'next','utid':utid,'answer':answer}
});
}
});


springACTION里:

public ModelAndView updateUT(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//上一题,下一题,完成
String act = (request.getParameter("act")==null)?"next":request.getParameter("act");
String utid = request.getParameter("utid");
int pos = (request.getParameter("pos")==null)?0:Integer.parseInt(request.getParameter("pos")); //位置
String answer = (request.getParameter("answer")==null)?" ":(String)(request.getParameter("answer"));
System.out.println("------------------"+utid+" ****** "+pos+" "+answer);

//下一题
if(act.equals("next")){
//保存答案

//显示下一题
List qs = (request.getSession().getAttribute("qs")==null)?null:(List)request.getSession().getAttribute("qs"); //qL是题目集
if(qs.size()>0){
pos = (pos >= (qs.size()-1))?qs.size():pos;
request.getSession().setAttribute("question", qs.get(pos));
}
request.getSession().setAttribute("pos", pos);
return new ModelAndView("student/test");
}else if(act.equals("pre")){ //上一题

}

return null;

return new ModelAndView("student/test");跳转到student/test.jsp没反应
我单步执行,question的值是对的,就是显示不出来。

jsp里:

<form name="form1">
<table align="center" cellspacing='0' cellpadding='0' border="1" style="font-size: 14px;border: 1px solid #ccc;width:100%;">

<tr>
<td>题目名称:${sessionScope.question.subject}</td>
</tr>
<tr>
<td><input type="radio" name="answerId" value="A"/>选项A:${sessionScope.question.option1}</td>
</tr>
<tr>
<td><input type="radio" name="answerId" value="B"/>选项B:${sessionScope.question.option2}</td>
</tr>
<tr>
<td><input type="radio" name="answerId" value="C"/>选项C:${sessionScope.question.option3}</td>
</tr>
<tr>
<td><input type="radio" name="answerId" value="D"/>选项D:${sessionScope.question.option4}</td>
</tr>


<tr><td>
<input type="hidden" name="utid" id="utid" value="${sessionScope.question.id}"/>
<input type="hidden" name="pos" id="pos" value="${sessionScope.pos}"/>
<input type="button" name="btPre" id="btPre" value="<" style="width:50px;height:25px;"/>
<input type="button" name="btNext" id="btNext" value=">" style="width:50px;height:25px;"/>
<input type="button" name="btOk" id="btOk" value="完成" style="width:50px;height:25px;"/>
</td></tr>
</table>
</form>

还有就是JSP放在iframe里。
...全文
239 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hooligan00011 2012-12-11
  • 打赏
  • 举报
回复
是这样啊,我现在就是搞不清楚什么时候用$.ajax,什么时候用平常form.action
torytin 2012-12-11
  • 打赏
  • 举报
回复
你写的代码只是在btNext上面加了一个click事件,按你的代码逻辑后台返回是成功的,但是页面不会刷新,除非你把$.ajax的返回结果直接赋给iframe框架的内容。但这样会很不合常规的做法,你这个根本没必要用ajax调用。ajax的目的是页面部分刷新,但是你后台返回的是整个页面内容,已经没必要用ajax调用了,而是应该用普通的表单提交,正确的做法应该是btNext和另外几个点击成功后需要刷新页面的按钮类型应该是submit的,然后form的action="updateUT.do",method="post",然后你在form的submit事件里面做答案是否为空等的判断。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧