Ich habe 3 JSONArrays
und JSonobject
, die ich als success response
in ajax
zurückgeben möchte.mehrere JsonArrays und JSONObject für Ajax return success?
Ich habe
erstelltout.print(jarrayTable);
out.print(jarrayChartTotalMF);
out.print(jarrByAgeGroup);
out.print(objTotal);
Ich weiß nicht, wie die Daten in ajax - jquery
zu erhalten. Ich habe versucht, das Programm mit einem JSONArray
und es funktioniert perfekt, aber
ich weiß nicht, laufen, wie mehrere erstellen arrays and a object and parsing
sie in jquery
Variablen in return success of ajax.
Ich habe auch versucht, dies zu tun, aber ich weiß nicht, wie zu analysieren die Daten in 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);
ich bin derzeit immer diese reults, wie ich die Daten in jquery erhalten Sie
[{"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...
das ist, was ich bekomme, wenn ich es von console.log(JSON.stringify(data));
mit auf Konsole aus, aber wenn ich versuche, die Variable/Daten zu erhalten console.log("HELLO" +print[0].ByAgeGroupSexTable[0].location);
dies war die error
Cannot read property '0' of undefined
Das ist mein JS-Code
$("#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);
}
});
}));
, aber ich habe auch eine JSONObject – SCS
Beispielausgabe: [{} [], [], []] –
Post vollständige Ausgabe hier oder eine neue Frage erstellen. Was ich die Antwort sehen kann, ist hier nicht abgeschlossen :( –