I need to send ajax request to java back-end and to response (from java back-end) with two html-blocks as answer. I want to generate those two html-blocks using two different JSPs. I do this as following:
req.setAttribute(...);
...
resp.setContentType("text/html");
RequestDispatcher dispatcher = req.getRequestDispatcher("one.jsp");
dispatcher.include(req, resp);
dispatcher = req.getRequestDispatcher("two.jsp");
dispatcher.include(req, resp);
And it works. But on the front-end I receive an answer like one solid html code (rendered one.jsp + rendered two.jsp). But I need to receive it as two separate html blocks to put each block to it's own . What is the proper way to do this?
Ajax code:
function addNew() {
var request = $.ajax({
url: "myUrl",
type: "post",
dataType: "html",
success: function(data) {
$("#divNameOne").html(<one part of data>);
$("#divNameTwo").html(<second part of data>);
},
error:function() {
alert("fail");
}
});
}