加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax中使用Json传递数据

发布时间:2020-12-16 00:58:08 所属栏目:百科 来源:网络整理
导读:首先在Action中将ques对象放进Json对象中 JSONObject obj = new JSONObject(); obj.put("quesid",ques.get("quesid").toString()); obj.put("content",ques.get("content").toString()); obj.put("options",ques.get("options").toString()); obj.put("answe


首先在Action中将ques对象放进Json对象中

JSONObject obj = new JSONObject();

obj.put("quesid",ques.get("quesid").toString());
obj.put("content",ques.get("content").toString());
obj.put("options",ques.get("options").toString());
obj.put("answer",this.parseXml(ques.get("answer").toString()).toString());
obj.put("uanswers",uanswers);
obj.put("quesType",ques.get("type").toString());
log.info(obj.toString());
setJsonString(obj.toString());

return JSON_RESULT;

然后在前台页面中获取数据

$.getJSON("${base}/exam/test!answerQuestion.action",{"examId":examId,"type":type,"answeredNum":answeredNum,"examUserId":examUserId,"answer":answers,"quesId":quesid},function(data){ //赋值 $("#buffer").text(""); quesid=data['quesid']; $("#resources_ce3_content_test_left_center_1 span p").html("第 "+(answeredNum+1)+" 题"); var content=$("#buffer").text(data['content']).html(); $("#resources_ce3_content_test_left_center_2 span p").html(content); quesType=data['quesType']; //解析xml格式的试题选项 options=data['options']; //解析xml格式的试题答案 uanswers=data['uanswers']; //alert("试题答案"+uanswers); var str=loadXML(options); var ops = str.getElementsByTagName("o"); 。。。。省略

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读