从jsp页面获取ajax请求数据

时间:2016-07-29 04:26:29

标签: javascript java jquery ajax jsp

我在JSP中有这个代码

        Map<String, Long> map = new HashMap<String, Long>();
        map.put("A", 10L);
        map.put("B", 20L);
        map.put("C", 30L);

        JSONObject json = new JSONObject();
        json.accumulateAll(map);

        System.out.println(json.toString());


        List<String> list = new ArrayList<String>();
        list.add("Sunday");
        list.add("Monday");
        list.add("Tuesday");

        json.accumulate("weekdays", list);
        System.out.println(json.toString());

打印

Info:   2
Info:   {"A":10,"B":20,"C":30}
Info:   {"A":10,"B":20,"C":30,"weekdays":["Sunday","Monday","Tuesday"]}

在netbeans的输出中

我的ajax是

var id = $(this).attr('data-id');

$.ajax({
    type: 'POST',
    url: '../include/residents.jsp',
    dataType: "json",
    data: {
        id: id,
    },
    success: function(data) {},
    error: function(data) {}
}).done(function() {
});

如何在ajax成功或完成功能中显示这些输出数据?

1 个答案:

答案 0 :(得分:0)

尝试输出json一次

System.out.print(json);
System.out.flush();
ajax中的

使用appendeach的组合来循环工作日