I can't get this simple ajax code to work

CDnahunwina

New Member
I am starting to learn about ajax with jquery and I've tried a lot of googling and I can't get this test code to work can you tell me what am I doing wrong? What happens is that the ajax won't create the table. Here is my code:The JSP:\[code\]<html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="http://stackoverflow.com/questions/10537790/js/jquery.js"></script> <title>My First Web App</title> <script type="text/javascript"> $(document).ready(function{ $.ajax({ type: "GET", url: "users", dataType: "xml", success: function(xml){ $("#content").append("<table>"); $(xml).find("user").each(function(){ var firstName = $(this).find("firstName").text(); var lastName = $(this).find("lastName").text(); var password = $(this).find("password").text(); var email = $(this).find("email").text(); $("#content").append("<tr>"); $("#content").append("<td>" + firstName + "</td>"); $("#content").append("<td>" + lastName + "</td>"); $("#content").append("<td>" + password + "</td>"); $("#content").append("<td>" + email + "</td>"); $("#content").append("</tr>"); }); $("#content").append("</table>"); } }); }); </script></head><body> <div id="content"></div></body>\[/code\] The servlet:\[code\]@WebServlet("/users")public class users extends HttpServlet {private static final long serialVersionUID = 1L;/** * @see HttpServlet#HttpServlet() */public users() { super(); // TODO Auto-generated constructor stub}/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml;charset=UTF-8"); usuarioDAO uDAO = new usuarioDAO(); response.getWriter().write(uDAO.getAllUsers());}\[/code\]usuarioDAO:\[code\]public String getAllUsers(){ String xml = ""; xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; xml += "<users>"; try { getAllUsers = con.prepareStatement("SELECT * FROM users"); synchronized(getAllUsers) { ResultSet res = getAllUsers.executeQuery(); while (res.next()) { xml += "<user>"; xml += "<firstName>" + res.getString("firstName") + "</firstName>"; xml += "<lastName>" + res.getString("lastName") + "</lastName>"; xml += "<password>" + res.getString("password") + "</password>"; xml += "<email>" + res.getString("email") + "</email>"; xml += "</user>"; } } getAllUsers.close(); } catch (Exception ex) { System.out.println(ex); } xml += "</users>"; return xml;}\[/code\]And that's about it, can you please tell me what am I doing wrong?
 
Back
Top