AJAX Interview Questions & Answers

Have you ever used Google Maps to find your favorite destination? If yes, then you have interacted with AJAX based web application. Following are the top 16 AJAX Interview Questions that are designed for you to crack the interview.

1) What is the full form of AJAX?

AJAX stands for Asynchronous JavaScript and XML.

2) What is the definition of AJAX?

AJAX is the technique of exchanging data with a server and updating parts of a web page without reloading the entire page.

3) What are the benefits of AJAX?

Following are the benefits of AJAX -

  • Cross-browser & cross-platform compatibility
  • Better & richer user experience
  • Web programming flexibility
  • Reduced consumption of server resources

4) What does AJAX do?

It exchanges the data between client and server and the data is in the form of text, XML, or JSON.

5) The web page that is downloaded from the web server contains?

HTML, CSS, and JavaScript.

6) What are the functionalities provided by XMLHttpRequest?

  • Update a web page without reloading the entire page.
  • Request receive and send data in the background after the page has loaded.

7) What is synchronous request in AJAX?

In synchronous request, the usual working of a page and user interaction is blocked until a response is received from the server.

8) What is asynchronous request in AJAX?

In an asynchronous request, the page continues to work normally without blocking the user. It is the most preferred way of sending a request.

9) What are the properties of XMLHttpRequest?

There are six properties of XMLHttpRequest-

Properties Explanation
onreadystatechange Use to specify the function name that will be invoked whenever the value of readyState changes.
readyState It contains the status of XMLHttpRequest object. The Range of this property is from 0 to 4.
0- request is not generated
1- connection with the server is made
2- the server receives request
3- request is processing
4- response is received, and request is finished
responseText It stores the response data in the form of string.
responseXML It stores the XML data received in response.
status Returns the status code(200 for OK, 403 for Forbidden, 404 for Not Found, and so on)
statusText It holds the text of the status.

10) What are the functions of XMLHttpRequest?

Functions Explanation
abort() This function is used to cancel the current request.
getAllResponseHeaders() It returns all the response headers in the form of a string.
getResponseHeader() This function returns the value of the specified header.
open(method,url,async,uname,pswd) This method is used to initialized the request. It takes the following arguments -
method- the type of HTTP method such as GET, POST, etc.
url- Specifies the file on the server to send the request to.
async- It is optional, and by default it is true. A false value indicates that the request must be handled synchronously and true value indicates asynchronously.
username & password- Optional and by default it is null. Use for authentication purposes.
send(string) It sends the request to the server. If the HTTP method of a request is POST, then the argument of this function is not ignored.
setRequestHeader(header, value) This methods must be called before send() method and after open() method. It is used to set the header of HTTP request.

11) How many types of readyState are there in AJAX?

Following table lists the types of readyState-

Types Description
0 request is not generated.
1 connection with the server is made.
2 the server receives request.
3 request is processing.
4 response is received, and request is finished.

12) How can you debug AJAX application?

If you want to debug in Google Chrome, then use Chrome Developer Tool. On Mozilla Firefox, with the help of Firebug, debugging can be done easily.

13) Can you provide any real world example of AJAX?

Nowadays, many websites and web applications are using AJAX. Some of the most popular web applications are-

  • Google Maps
  • Youtube
  • Instagram
  • Google Plus
  • Twitter
  • Facebook

14) What are disadvantages of AJAX?

Every technology is not a perfect and has some disadvantages. The cons of AJAX are-

  • Source code of AJAX is viewable.
  • It depends on javascript and cannot work if javascript is disabled in a web browser.
  • Malicious code can be inserted into the system.

15) What is Rich Internet Application (RIA)?

An application that works similar to a desktop application and has enhanced the user interface, advanced functions and quicker response time.

16) What are the most popular AJAX framework?

  • Angular JS
  • Backbone.js
  • Prototype
  • Ext JS
  • jQuery and jQuery UI