zhangzijiez
2018-03-09 13:09
采纳率: 38.5%
浏览 1.1k
已采纳

ajax 不走success函数 请教大神

 mapper:
<select id="getDate" resultType="org.his.beans.OutBound">
    select distinct ny from OutBound order by ny desc
</select>
 controller:
@RequestMapping("/main")
    @ResponseBody
    public ModelAndView main(HttpServletResponse response, ModelAndView mv, HttpServletRequest request) {
        try {
            List<OutBound> list = service.getDate();
            JSONArray jsonArray = JSONArray.fromObject(list);
            mv.addObject("jsonArray",jsonArray);
            System.out.println(jsonArray);
            return mv;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 jsp:
    <script type="text/javascript">
    $(document).ready(
            function() {
                $.ajax({
                    type : "POST",
                    url : "main",
                    dataType : "json",
                    success : function(data) {
                        alert(data);
                        for (var i = 0; i < data.length; i++) {
                            $("#ny").append(
                                    "<option>" + data[i].NY + "</option>");
                        }
                    }
                });
            });
</script>

8条回答 默认 最新

相关推荐 更多相似问题