retrieve more than one value by JSON array objects

后端 未结 1 1802
情歌与酒
情歌与酒 2020-12-12 06:26

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:

 

        
1条回答
  •  半阙折子戏
    2020-12-12 07:05

    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 options = new Map();
     //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($('

    0 讨论(0)
提交回复
热议问题