0

I have the following jsp

<c:forEach items="${vlocomotoras}" var="vl" varStatus="i">

    <select class="regimenFrenoLocomotora" id="regimenFrenoLocomotora" name="regimenFrenoLocomotora" onchange="calcularDocumentoTren();">
        <option value="P" ${"P" == v1.regimenFrenoLocomotoras ? 'selected="selected"' : ''}>P</option>
        <option value="G" ${"G" == v1.regimenFrenoLocomotoras ? 'selected="selected"' : ''}>G</option>

</select>

</c:forEach>

I have the following ajax post to a servlet

$.ajax({
            type: "POST",
            url: "/copernico/SrvRenfeSituacion",
            data: {
            "arrayLocomotora[]" : arrayLocomotora,
            todo:todo,
            fecha:fecha,
            tren:tren
          },
            error:function(){
            console.log("ERROR");
          },
            success:function(responseText){
            alert('responseText ');
            alert(responseText);
            alert("Success");
          }
        });

This is the servlet

req.setAttribute("vlocomotoras", locomotoras);

Now I want to refresh the drop down with the new values of vlocomotoras. How can I do this?

Carlota
  • 1,239
  • 3
  • 29
  • 59

1 Answers1

0

Have your servlet return a json array with the data you need. See this question for doing that.

(In the ajax call, set dataType="json" for the call to expect a json object as response)

Once you get the json object in the ajax response, you can replace the OPTION tags inside the SELECT using jQuery (empty() and appendTo()).

Juan
  • 5,525
  • 2
  • 15
  • 26