let's say I have this code in javascript:
function doAnAjaxCall () {
var xhr1 = new XMLHttpRequest();
xhr1.open('GET', '/mylink', true);
xhr1.onreadystatechange = function() {
if (this.readyState == 4 && this.status==200) {
alert("Hey! I got a response!");
}
};
xhr1.send(null);
}
and let the code in the servlet be:
public class RootServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.getWriter().write("What's up doc?");
resp.setStatus(200);
}
}
Will xhr1 still wait for new changes in readystate? Or it is closed as soon as it gets the first response? If it remains open, will it lead to memory leaks/slower browser after a while and accumulating a few of those? Should I always call resp.getWriter().close() at the end of the servlet code?
And, lastly, for the jQuery fans out there:
does $.ajax()
behave as XMLHttpRequest()
in that respect?