Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

ajax

can anyone tell me. What exactly is Ajax request? Is it different from Servlet Request?

like image 447
user241924 Avatar asked Jan 25 '10 04:01

user241924


People also ask

What is the difference between XMLHttpRequest and AJAX?

XHR is the XMLHttpRequest Object which interacts with the server. Ajax technique in the nutshell leverages the XHR request to send and receive data from the webserver. This object is provided by the browser's javascript environment. It transfers the data between the web browser and server.

What are the 4 steps of an AJAX request?

Steps of AJAX OperationAn XMLHttpRequest object is created. The XMLHttpRequest object is configured. The XMLHttpRequest object makes an asynchronous request to the Webserver. The Webserver returns the result containing XML document.

What type of request is AJAX?

The ajax() methods performs asynchronous http request and gets the data from the server. The following example shows how to send a simple Ajax request.

How should I use servlet and AJAX?

You can in the servlet distinguish between normal requests and Ajax requests as below: @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String foo = request. getParameter("foo"); String bar = request.


1 Answers

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.

like image 73
cletus Avatar answered Sep 19 '22 14:09

cletus