title: calling servlet from php page using ajax
body: <p>i am trying to get response from servlet page and displaying alert on success. but its show me error always. i am not able to figure it out.</p>
  
  <p>My ajax code:</p>
  
  <pre><code>$(document).ready(function() {
  $("#srch").click(function() {
   var txt1 = $("#store-qsearch").val();
   alert(txt1)
   $.ajax({
              url : 'http://localhost:8080/searchengine/SearchDataServlet',
              data : 'val='+txt1,
              type : 'GET',
              success : function(response) {
                  alert("Success");
                  // create an empty div in your page with some id
              },
              error: function(){ alert("error");
  
              }
          });
  });
                         });
  </code></pre>
  
  <p>My servlet code:</p>
  
  <pre><code>public class SerachDataServlet extends HttpServlet {
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      String searchkey = request.getParameter("val").toString();
      SearchInput searchinput = new SearchInput();
      searchinput.searchkeys = searchkey;
  
      System.out.println(searchkey);
      SearchParser searchparser = new SearchParser();
      searchparser.searchData(searchkey);
  
  
      PrintWriter output = response.getWriter();
      output.println("successs");
  
  
  }
  
  }
  </code></pre>