为什么ajax的success在页面返回的是字符串

 $.ajax({
        url : url,
        type : 'post',
        dataType: 'json',
        data : datastring,
        success : function(data) {
            alert(3);
        },
        error:function(data) {
            alert("error");
        }
    });

    controller中
        @RequestMapping("/insertMenu")
    @ResponseBody
    public MenuVo insertMenu(MenuSunVo menuSunVo,HttpServletResponse response) throws IOException {  
//      response.setCharacterEncoding("UTF-8"); 
//      String success = "nimabi";
//      JSONObject json = new JSONObject();
//      json.put("success", "success");
//      response.getWriter().print(json.toString());  
//      response.getWriter().flush();  
//      response.getWriter().close();
//      System.out.println(menuSunVo.getMenuName());
        MenuVo menuVo = new MenuVo();
        menuVo.setMenuId("1");
        menuVo.setMenuName("name");
        return menuVo;
    }
注释的部分和没注释的都试过,这两个都会直接把结果显示在页面。
为什么不会alert(3),而是直接在页面显示出结果,怎么才能让他进入到success中。

返回结果如图所示   回答的第一条就是图片。。
![图片说明](https://img-ask.csdn.net/upload/201704/16/1492314904_914418.png)

$.ajax({
url : url,
type : 'post',
dataType: 'json',
data : datastring,
success : function(data) {
alert(3);
},
error:function(data) {
alert("error");
}
});
这段代码在什么情况下调用
除了这段代码,你的界面还绑定了什么别的请求服务器,post的代码

图片说明

因为你后台设置返回的就是 json

你怎么处罚的ajax的。放表单里面的submit按钮?表单提交了吧,否则ajax没看你操作dom对象不可能显示返回的内容的

要注意阻止表单提交

 <input type="submit" onclick="yourfunction();return false;"

看着像是使用的springmvc框架。 首先要确认的是, 你图片显示的返回值不是字符串, 而是一个json对象。
controller方法上的@ResponseBody注解,就是将返回值转换为json对象。 可以在alert的地方设置一个断点看看。
如果浏览器阻止了弹窗, 那就真的看不到alert的效果了。 不知道你这个菜单窗口是什么软件。 看起来不像是浏览器呀

看你后台的servlet 怎么写的