Is it possible to send ajax request to the server, store the HttpServletResponse Object there and send a response at any time to the clent?
$.get({ url: '/startChat', async: true, success: function (msgToAdd, textStatus, jqXHR) { alert(msgToAdd) }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); } }); Server:
private HttpServletResponse firstResponse; @RequestMapping(value = "/startChat", method = RequestMethod.GET) public void startUserChat(HttpServletRequest request, HttpServletResponse response) { firstResponse = response; } Later use the saved firstResponse object to send a message to the success function ajax
I tried to do this, my-message comes to the success function, but with some strange pattern of 90%, it is, and the randomness pattern.
Checked the httpServletResponse object is the same in the case when msg is attached and when not.