I am writing a servlet that will accept POST data coming from an AJAX request.
Here is the code I send from the client:
$.ajax({
type: "POST",
url: "urlservlet",
data: "{type:'" + "country" +
"', country:'" + $('#country').val() +
"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
}
And this is the servlet code:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
string test = request.getParameter("type");
}
But the thing is I always get the type equal to null. I don't know why.
Kindly help me.