2

I have this code in 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());

It prints

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

In netbeans's ouput

my ajax is

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() {
});

How can I show those ouput data in ajax success or done functions?

guradio
  • 15,524
  • 4
  • 36
  • 57
Brownman Revival
  • 3,620
  • 9
  • 31
  • 69

1 Answers1

0

Try outputting you json once

System.out.print(json);
System.out.flush();

in ajax use a combination of append and each to loop the weekdays

madalinivascu
  • 32,064
  • 4
  • 39
  • 55
  • i use `out.println(jsonMap.toString());` it shows now in Preview problem is the format is wrong not json output is like `{ fname = John, lname = Smith }` so the `jsonMap.put( "lname", lname ); jsonMap.put( "fname", fname );` is wrong any idea how to make it put data like json out put? – Brownman Revival Jul 29 '16 at 04:47
  • got it i used `JSONObject json = new JSONObject();` then `json.put( "lname", lname ); json.put( "fname", fname );` thanks for ideas :)\ – Brownman Revival Jul 29 '16 at 04:48