Reputation: 2427
I've written a simple servlet for processing an Ajax request. On the server side, the doPost
is called, but the data that I've set in the response object is not reflected on the client. (Actually, I'm not getting anything on the client according to Firebug). I'm using jQuery to handle the Ajax.
Client code:
$.post(
'/mapped/url?param=' + $('#eleId').val(),
function(data){
alert(data);
},
"xml"
);
On the server:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("!!!In post!!!!");
// some calculations go here
response.setContentType("application/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<data><param number=\"\"></param></data>");
response.setStatus(HttpServletResponse.SC_OK);
}
Thanks in advance!
Upvotes: 2
Views: 2531
Reputation: 7580
You may have to explicitly close the output stream -
PrintWriter out = res.getWriter();
out.println( "Sample response" );
out.close();
Upvotes: -1
Reputation: 6760
You need to debug this in steps as this issue could mean anything from improper Servlet configuration to a bug in the client side code.
Upvotes: 4