Java is not a language with training wheels. It is a language for professional programmers.

— Hebert Sheildt

Ajax Call With Java

AJAX stands for Asynchronous Javascript and XML. Every browser (new ones) provides an XMLHttpRequest object to make HTTP request to the server via Javascript. Asynchronous in AJAX means that the script execution won’t stop when the request to the server is made. In other words, the user can continue working on the current page and not wait for the server’s response.

This is why AJAX is asynchronous, we can however make AJAX synchronous i.e the script execution will stop until the server response is gathered, not recommended.

Ajax calls are generally made with the help of a Javascript framework like jQuery,Prototype,etc. Here I am going to use plain Javascript.


There are certain important properties of the XMLHttpRequest object:

1. status -- It is the HTTP status code for the response.

2. responseText -- It is the response text from server.

3. readyState -- It denotes states as :


0 – UNINITIALIZED, 1 – LOADING, 2 – LOADED, 3 – INTERACTIVE, 4 – COMPLETE.


Here I use a simple Servlet to gather a list of products from MySQL database.

AjaxTest.java



ajax.js



Ajax can be made synchronous,no recommended.When ajax is forced to be synchronous (by setting false),Javascript execution is put on hold until the response is achieved from the server.


© Copyright © 2013 SourabhBawage.com. All Rights Reserved.