0

Hi I am trying to populate a combobox using ajax, but I cant get it work. This is my code, I get the data from a Servlet.

 $.ajax({
     type: "POST",
     url: "../../sListarProvincia",
     data: dataString,

     success: function (data) {
         $("#cboProvincia").append(data);
     },
     error: function (data) {
         alert("ocurrio un error");
     }
 });

Here is the code on my Servlet.

    try {
        /* TODO output your page here. You may use following sample code. */
        String IdDepartamento = request.getParameter("IdDepartamento").toString();
        List<Ubigeo> lisUbigeo = UbigeoCOM.ListarProvincias(IdDepartamento);

        String html="";
        for(int i=0;i<lisUbigeo.size();i++)
        {
            html = html + "<option value="+lisUbigeo.get(i).getIdUbigeo()+">"+ lisUbigeo.get(i).getNombre()+"</option>";

        }

        out.println(html);

My html:

<select style="float:left" id="cboProvincia" class="combobox" name="cboDepartamento">
</select>
Flezcano
  • 1,647
  • 5
  • 22
  • 39

1 Answers1

2
  • If your select element has the ID cboProvincia in view source,
  • If your success function fired,
  • If your data is something to <option>...</option>,

Then this code must works correctly:

$("#cboProvincia").html(data);