java - Pass json to dropdown -
how store list in servlet in options of dropdown? equivalent jquery if values of age stored value of option of dropdown , name display in dropdown
public class testservlet extends httpservlet { protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("application/json"); printwriter out = response.getwriter(); list<student> studlist = new arraylist<student>(); student s1 = new student(); s1.setname("student 1"); s1.setage(10); student s2 = new student(); s2.setname("student 2"); s2.setage(14); gson gson = new gsonbuilder().setprettyprinting().create(); string json = gson.tojson(studlist); out.print(json); } }
try:
$(document).ready(function() { $('#student').ready(function(event) { $.get('studentservlet',function(responsejson) { var $select = $('#student'); $.each(responsejson, function(studlist) { $('<option>').val(this.['age']).text(this['name']).appendto($select); }); }); }); });
$(document).ready(function() { $('#student').ready(function(event) { $.get('studentservlet',function(responsejson) { var $select = $('#student'); $.each(responsejson, function(studlist) { $('<option>').val(this.['age']).text(this['name']).appendto($select); }); }); }); });
Comments
Post a Comment