String from Java Servlet to HTML via jQuery
Hey,
I have some problems with jQuery:
I want to generate dynamic html code via java serlvets.
from the class LightServlet
- public void getAllLights(HttpServletRequest request,
- HttpServletResponse response) throws IOException,
- NumberFormatException, InvalidSyntaxException {
- response.setContentType("text/xml");
- PrintWriter out = response.getWriter();
- out.println("<div><report>");
- for (int x = 0; x < l.getLightAmount(); x++) {
-
- String status;
- if (l.checkLight(x) == true) {
- status = "on";
- } else
- status = "off";
- out.print("<form name='form' type='get' method='post'>");
- out.print("<input type='button' class='setLampsClass' name='setLampID' "
- + "id='setLampID_"+x+"' onclick='setlamp(" + x + ");' value='Set your light'/></form>");
- }
- out.println("</report></div>");
- out.flush();
- out.close();
-
-
- out.flush();
- out.close();
- }
The code will be generated and I can see the code via firebug:
- <report>
- <form name="form" type="get" method="post">
- <input type="button" class="setLampsClass" name="setLampID" id="setLampID_0" onclick="setlamp(0);" value="Set your light"/>
- </form>
- <form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_1" onclick="setlamp(1);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_2" onclick="setlamp(2);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_3" onclick="setlamp(3);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_4" onclick="setlamp(4);" value="Set your light"/></form></report>
However the div tag, in which the generated html code should be inserted to, remains empty.
jQuery Function:
- $("#getAllLights").click(function() {
- $.post("LightServlet", {
- ALL : 1
- }, function(xml) {
- $("#all").html($("report", xml).text());
- });
- });
I think, the problems should be in the jQuery code, because it works with normal strings without any html tags.
Thanks!