(前端)
<input type="submit" onclick="answersSubmit()" value="提交答案" /> </div> </form>
(ajax) //以下为提交答案 function answersSubmit(){ //提交答案
$.ajax({ //几个参数需要注意一下 type: "POST",//方法类型 dataType: "json",//预期服务器返回的数据类型 url: "/answersSubmit" ,//url async:false, data: $('#myform').serialize(), success: function (result) { console.log(result);//打印服务端返回的数据(调试用) if (result.resultCode == 200) { console.log("提交答案返回数据"+result); } ; }, error : function() { alert("异常!"); } }); }
(后端) @RequestMapping(value = "/answersSubmit",produces = "text/html;charset=UTF-8") @ResponseBody public String answersSubmit(HttpServletRequest request) throws ParseException { String answerId = request.getParameter("answerId"); String userAnswer = request.getParameter("inputArr");
Gson gson = new Gson(); return gson.toJson(rightorerror); }