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);
}
}