Ajax中使用Json传递数据

前端之家收集整理的这篇文章主要介绍了Ajax中使用Json传递数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


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

猜你在找的Ajax相关文章