1

I creating a Java web application with an action file which generates data from database to a JSON array. Now, I want this JSON array to be passed to jQuery? How is that possible?

FYI. I applied Struts 2, Spring and Hibernate frameworks. I am not using PHP for this app.

Update:

This is my Struts 2 action method:

public static String jsonData = null;

public String generateJson() throws Exception
{
    JSONObject json = null;
    JSONArray jsonArray = new JSONArray();

    this.records = this.recordManager.getAllRecords();

    for (RecordEntity record : records)
    {
        json = new JSONObject();

        json.put("id", record.getId());
        json.put("firstname", record.getFirstName());
        json.put("lastname", record.getLastName());
        json.put("due", record.getDue());
        json.put("email", record.getEmail());
        json.put("website", record.getWebsite());
        jsonArray.put(json);
    }

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

    jsonData = jsonArray.toString(); // jsonData will be passed to jQuery
    return SUCCESS;
}

And this is my jQuery. I am using BootstrapTable so this is the structure, and I want the value of jsonData to be passed to this jQuery:

$('#record').bootstrapTable({
    method : 'get',
    data: jQuery.parseJSON(VALUE_OF_jsonData_HERE),
    cache : ...
    ...
    ...
});
Dylan
  • 13
  • 8

1 Answers1

0

Using Ajax will help you,

refer this to get started, also do read about Ajax first to have a background

Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
  • Yes, I already used that. Please note I have modified the question and added the codes. :) – Dylan Dec 06 '14 at 15:46