簡體   English   中英

如何將Struts 2動作類的JSON數組傳遞給jQuery?

[英]How to pass JSON array from Struts 2 action class to jQuery?

我用操作文件創建了一個Java Web應用程序,該文件將數據從數據庫生成到JSON數組。 現在,我想將此JSON數組傳遞給jQuery嗎? 那怎么可能?

僅供參考。 我應用了Struts 2,Spring和Hibernate框架。 我沒有為此應用程序使用PHP。

更新:

這是我的Struts 2操作方法:

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;
}

這是我的jQuery。 我正在使用BootstrapTable,所以這是結構,我希望將jsonData的值傳遞給此jQuery:

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

使用Ajax將為您提供幫助,

請參考入門,也要先閱讀有關Ajax的背景知識

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM