Retrieve More Than One Value By JSON Array Objects
I am getting one value by JSON array, but how can I store multiple values in JSON array and how can I retrieve it by JavaScript? auto.jsp:
Solution 1:
I think you are getting only 5 in your second combo because you are making an error in your loop. You could do
//in combo1.jsp
String selectedValue = request.getParameter("count");
Map<String, String> options = new Map<String, String>();
//get your data from db
while(rs.next()){
String t1=(String)(rs.getString(1));
options.add(t1, t1);
}
String json = new Gson().toJson(options);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
//to get data
$.getJSON('combo1.jsp', {
count: this.value
}, function(options) {
var dropdown2 = $('#combo1');
$('>option', dropdown2).remove(); // Clean old options first.
if (options) {
$.each(opts, function(key, value) {
dropdown2.append($('<option/>').val(key).text(value));
});
} else {
dropdown2.append($('<option/>').text("Please select dropdown1"));
}
});
Post a Comment for "Retrieve More Than One Value By JSON Array Objects"