NieXiaoHui

最近在做实习时,点击查询时在js中发送ajax请求到controller后台,但是无论怎么样都不成功,请求地址是正确的,因为在后台用system.out.println输出有值,并且也确实return了,后来百度才发现在springmvc注解中.必须要加上@ResponseBody注解,ajax请求才会成功.

后台部分代码:

    @RequestMapping("select.do")
    @ResponseBody
    // 加入ResponseBody,才有返回值,ajax请求才能成功
    public String selectByDate(HttpServletRequest request, Model model) {
        String begin_Date = request.getParameter("begin_Date");
        List<MobileManage> list = getDataList(begin_Date);
        JSONArray json = JSONArray.fromObject(list);
        String paseJson = paseJson(list);
        // System.out.println(json.toString());
        return paseJson;
    }
View Code

前台部分代码:

$.ajax({
                       type:"post",
                       url:"/mylog/mobileManage/select.do",
                       dataType:"json",
                       data:{begin_Date:begin_Date},
                       success:function(data){
                                        //处理
                                    }    
})                            
View Code

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-11-08
相关资源
相似解决方案