Ajax中使用Json传递数据

来源:互联网 发布:淘宝上有没有微信号卖 编辑:程序博客网 时间:2024/05/02 00:01


首先在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");
              
               。。。。省略


原创粉丝点击