What exactly is Ajax request? Is it different from Servlet Request?

An Ajax call is an asynchronous request initiated by the browser that does not directly result in a page transition. A servlet request is a Java-specifc term (servlets are a Java specification) for servicing an HTTP request that could get a simple GET or POST (etc) or an Ajax request.

An Ajax (“Asynchronous Javascript and XML”) request is sometimes called an XHR request (“XmlHttpRequest”), which is the name most browsers give the object used to send an Ajax request, because at least initially Ajax calls involved the sending and receiving of XML but now it’s just as common to send/receive JSON, plain text or HTML.

A good example of an Ajax request is the comment system on Stackoverflow. You can enter a comment in the textbox and click submit. It doesn’t submit the whole page (like a traditional HTML form submission would, which translates into usually a POST but sometimes a GET HTTP request). Instead the browser will send probably a POST request via XHR to the server and be notified of the response (hence “asynchronous”). But the server typically can’t distinguish between an Ajax request or a page transition because both simply come down to HTTP requests.

Leave a Comment