ajax调用中的空响应

时间:2016-02-26 13:38:36

标签: jquery ajax

function callQueAjax()
                            {
                            var str = $("#addNewQues").serialize();
                            $.ajax({
                                            type : "POST",
                                            data : JSON.stringify(str),
                                            url : "postNewQues",
                                            dataType: "json",
                                            contentType: "application/json",
                                            success : function(res) {
                                            //alert("yay");
                                            alert("res>>>>>"+res);

                                            },
                                            error : function(e) {
                                                alert("error" + e);

                                            }
                                            });
                            }

当我发送表单数据时,它正确传递给我的控制器,但在响应中所有字段都为空,plz有助于在响应中获取正确的数据。如果我删除contentType: "application/json",我是获得400 Bad请求为错误。 控制器代码:

@RequestMapping(value = "/postNewQues", method = RequestMethod.POST)
    public @ResponseBody
    String submitNewQue(@ModelAttribute("EEAQBean") EEAQueBean eEAQBean) {
        // System.out.println("Obj.getReqTitle()>>>>>>"+Obj.getReqTitle());
        // Obj.getReqTitle();
        logger.info("IN Controller EEAss");
        logger.info("eEAQBean >>> "+eEAQBean.getReqId()+" >>>>> "+eEAQBean.getQueOrder());

        HashMap<String, Object> data = new HashMap<String, Object>();
        List<EEAQueBean> addNewQueList = new ArrayList<EEAQueBean>();

        // Long addNewReqId =0L;
        String addNewQueVal = "";
        String addNewQueCode = "";

        try {

            addNewQueCode = eeaServiceImpl.insertAddNewQueData(eEAQBean);

            eEAQBean.setAddNewQueCode(addNewQueCode);
            addNewQueList.add(eEAQBean);
            data.put("addNewQueList", addNewQueList);
            ObjectMapper mapper = new ObjectMapper();
            addNewQueVal = mapper.writeValueAsString(data);
            logger.info("addNewQueVal >>>>> " + addNewQueVal);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
        return addNewQueVal;
    }

0 个答案:

没有答案