title: jquery ajax calling servlet method and return json data
body: <p>I am new to Ajax programming I am using Jquery ajax my requirement to to fetch the data into server and display as table format.In that location must display radio button type.
  how to call servlet specific method how to return data.i am ready to use json.can any one help me how to call a method how to return a data.and suggestions require to solve the problem</p>
  
  <p>thanks in advance.  </p>
  
  <pre><code>$('#ajaxbutton').on('click',function(){
                  $.ajax({
                      type:"post",
                      url:"Db2",
                      data:{"labid",100},
                      sucess:function(){
                          alert("sucess");
                      }
  
                  });
              });
  </code></pre>
  
  <p>in servlet </p>
  
  <pre><code>public class Db2 extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws MalformedURLException, IOException {
          doProcess(request, response);
      }
  
      public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws MalformedURLException, IOException {
          doProcess(request, response);
      }
  
      public void doProcess(HttpServletRequest request,
              HttpServletResponse response) throws MalformedURLException,
              IOException {
          Connection con;
          PreparedStatement ps, ps1;
          PrintWriter out = response.getWriter();
  
          try {
  
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              con = DriverManager.getConnection("jdbc:odbc:oracle1", "system",
                      "sarath");
              ps = con.prepareStatement("select trackid,location,to_char(mydate,'dd-mon-yyyy') from information where labid=100");
              ResultSet rs = ps.executeQuery();
  
              while (rs.next()) {
                  String location = rs.getString(2);
                  String track = rs.getString(1);
                  String myDate = rs.getString(3);
              }
  
          } catch (Exception e) {
              out.println(e);
          }
  
      }
  }// end of ServletB
  </code></pre>