spring mvc+ajax 问转调查传参处理
2016-04-08 11:37
435 查看
$(function () { initQuestionnaireHtml(); }); var answers = []; function initQuestionnaireHtml() { $.ajax({ type: 'post', async: true, url: appPath.getRootPath() + "/survery/survery/getSurveryQuestion.do", dataType: "json", success: function (data) { if (data != null) { var dataHtml = ""; for (var i = 0; i < data.length; i++) { var question = data[i]; var answer = { "surveryQuestionid": question.id, "surveryQuestionnaireId": question.surveryQuestionnaireId, "answer": "" }; answers.push(answer); //"'+question.id+'", dataHtml += '<div class="form-group">' + '<label class="col-md-4 control-label" style="font-size:12px;" id="' + question.id + '">' + question.question + '</label>'; dataHtml += '<div class="col-md-8">' + '<select class="form-control" id="' + question.id + '" name="' + question.id + '" onchange="answerQuestion(this)">' + '<option value="" selected>-------请选择-------</option>'; var options = question.options; for (var j = 0; j < options.length; j++) { var questionOptionData = options[j]; dataHtml += '<option value="' + questionOptionData.code + '">' + questionOptionData.content + '</option>'; } dataHtml += '</select>'; dataHtml += '</div>'; dataHtml += '</div>'; } dataHtml += '<div class="form-group">' + '<div class="col-md-6">' + '<button type="button" class="btn btn-primary" style="margin-left:300px" onclick="saveInfo()">确定</button>' + '</div>' + '<div class="col-md-6">' + '<button type="submit" class="btn btn-primary ">取消</button>' + '</div>' + ' </div>'; $("#edit_form").append(dataHtml); } }, error: function () { alert('请求服务器出错!'); } }); }; function answerQuestion(element) { for (var i = 0; i < answers.length; i++) { var answer = answers[i]; var questionId = element.id; if (answer.surveryQuestionid == questionId) { answer.answer = element.value; break; } } } function saveInfo() { alert(JSON.stringify(answers)); $.ajax({ type: 'post', async: true, data:{"answersJson":JSON.stringify(answers)}, url: appPath.getRootPath() + "/survery/survery/ajaxSubmit.do", dataType: "json", success: function (data) { if (data) { alert("提交调查问卷成功"); }else{ alert("提交调查问卷失败"); } }, error: function () { alert('请求服务器出错!'); } }); }
相关文章推荐
- 《疯狂java讲义》笔记 1-5章
- java多线程web服务器
- HashMap浅析
- Java Socket编程
- JVM内存模型来解释多线程并发常见问题和volilate,final,ThreadLocal
- Java中String类型变量初值为null时的连接问题
- Java 程序死锁问题原理及解决方案
- Java Collection框架详解
- java CyclicBarrier 2
- java的mysql连库 增删改查语句、分页查询语句大全
- JVM、JRE、JDK
- java CyclicBarrier
- spring配置datasource的三种方式
- Java解析XML简单版
- Java的垃圾回收机制
- java之return解析
- Java 设计模式 <工厂模式>
- 当Spring同时使用了XML配置和注解
- Java学习之Iterator(迭代器)的一般用法
- Ehcache 整合Spring 使用页面、对象缓存