0

I am new to use AJAX methods. When the GET method is called, it sends a value as a parameter to the servlet which does the processing without a problem, but the doGet(request, response) returns the whole HTML code of the jsp instead of returning the string result which is in the shape of a JSON object.

Here is the JavaScript code:

$(document).ready(function() {
  $('#categoryProductID').change(function(event) {
    var cat=$("#categoryProductID").val();
    $.get('ServletController', {category:cat}, function(responseText){
      $('#subCategoryID').text(responseText);
    })
  })
});     

On the hand here is the servlet doGet code:

String categoriId = request.getParameter("category");
if(categoriId != null && !categoriId.equals("")) {
  sousCategorieDao.listerParIdCategorie(Long.valueOf(categoriId))) {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(categoriId);
  }
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • Hi , what do you mean by `whole HTML code of the jsp..`.? Can you elaborate more ? – Swati Sep 15 '20 at 16:39
  • I get the HTML tags after being transformed from jstl tags in the tag element subCategoryID instead of receiving JSON object – Soldier33 Sep 16 '20 at 20:43

0 Answers0