我有3 JSONArrays
和JSonobject
,我想返回success response
在ajax
。用於Ajax的多個JsonArray和JSONobject返回成功?
我創建
out.print(jarrayTable);
out.print(jarrayChartTotalMF);
out.print(jarrByAgeGroup);
out.print(objTotal);
我不知道如何獲得ajax - jquery
數據。我試圖用一個JSONArray
運行程序和它完美的作品,但
我不知道如何創建多個arrays and a object and parsing
他們進入jquery
變量return success of ajax.
我也試圖做到這一點,但我不知道如何解析jQuery中的數據
String json1 = new Gson().toJson(jarrayTable);
String json2 = new Gson().toJson(objTotal);
String json3 = new Gson().toJson(jarrayChartTotalMF);
String json4 = new Gson().toJson(jarrByAgeGroup);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
String AllJson = "[" + json1 + "," + json2 + "," + json3 + "," + json4 + "]"; //Put both objects in an array of 2 elements
response.getWriter().write(AllJson);
我目前得到這個reults,我如何在jQuery中獲取數據
[{"ByAgeGroupSexTable":[{"BothSexes":42,"AgeGroup":"Under 1","ApprovedBy":"Geraldine Atayan","Male":25,"Female":17,"location":"Barangay 1","UploadedBy":"Shermaine Sy"},{"BothSexes":42,"AgeGroup":"Under 1","ApprovedBy":"Geraldine Atayan","Male":25,"Female":17,..."arrByAgeGroup":[{"arrByAgeGroupBothSexes":0,"arrByAgeGroupMale":25,"arrByAgeGroupFemale":17,"arrByAgeGrouplocation":"Barangay 1","arrByAgeGroupAgeGroup":"Under 1"},{"arrByAgeGroupBothSexes":0,"arrByAgeGroupMale":25,"arrByAgeGroupFemale":17,"arrByAgeGrouplocation":"Barangay...
這是我所得到的,當我把它打印出來在控制檯上使用console.log(JSON.stringify(data));
但是當我試圖讓變量/數據console.log("HELLO" +print[0].ByAgeGroupSexTable[0].location);
這是error
Cannot read property '0' of undefined
這是我的JS代碼
$("#archived tbody").on("click", 'input[type="button"]', (function() {
var censusYear = $(this).closest("tr").find(".nr").text();
alert(censusYear);
var page = document.getElementById('page').value;
$.ajax({
url: "SetDataServlet",
type: 'POST',
dataType: "JSON",
data: {
censusYear: censusYear,
page: page
},
success: function (data) {
console.log(JSON.stringify(data));
var print = JSON.stringify(data);
console.log("HELLO" +print[0].ByAgeGroupSexTable[0].location);
...some other codess
}, error: function (XMLHttpRequest, textStatus, exception) {
alert(XMLHttpRequest.responseText);
}
});
}));
,但我也有一個JSONObject的 – SCS
輸出樣本:[{},[] [] [] –
安置自己的完整輸出這裏,或創建新的問題。我能看到的迴應是沒有在這裏完成:( –