Top 50 AJAX Interview Questions and Answers

The blog provides the Top 50 AJAX Interview questions and answers for experienced professionals. AJAX stands for Asynchronous JavaScript and XML used for developing fast and rich web applications. 

Many companies prefers developing UI using AJAX Technology and AJAX Interview questions and answers given below helps professionals to revise their AJAX knowledge.  

The below given includes basic and advanced AJAX questions and answers which could be helpful for the professionals for preparing UI /UX Job Interviews. 

AJAX Interview Questions and Answers

AJAX stands for Asynchronous JavaScript and XML used for developing fast and rich web applications using XMLHttpRequest object for communicating with the server without reloading the page.

The below given are the advantages of AJAX

  1. AJAX helps in developing fast and interactive web pages
  2. AJAX does not depend on server technology
  3. AJAX based requests uses less server bandwidth
  4. AJAX makes form validation simple

The below given are the disadvantages of AJAX

  1. AJAX is not supported by all browsers
  2. AJAX code is easy to read
  3. Malicious code can be inserted using custom script

AJAX can send and receive the data in JSON,XML and text file formats

The main features of AJAX are:

  1. Send the request to the server without reloading the page
  2. Receives and update the data received as server response

  1. Facebook
  2. Twitter
  3. Gmail

XMLHttpRequest objects are used to communicate with the server where the request is sent to the server in the background without reloading the page. It enables to make the partial page update without interrupting the user and is heavily used in AJAX programming.

XMLHttpRequest objects can be used to send and receive the data in various formats like JSON,XML and Text files.

The below given are the main properties of the XMLHttpRequest object

XMLHttpRequest Property Description
onReadyStateChange This is invoked whenever readystate attribute changes
readyState0- 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.
responseTextreturns the response in Text File Format
responseXMLreturns the response in XML Format
statusreturns the request status number
statusTextreturns the status details

The below given are the main methods of the XMLHttpRequest object

XMLHttpRequest Method Description
void open (method, URL)This method Opens the request specifying GET /POST method for the URL
void open (method, URL, async)This method Opens the request specifying GET /POST method for the URL for with additional parameter for asynchronous requests or not
void open (method, URL, async, username, password)This method Opens the request specifying GET /POST method for the URL for with additional parameter for asynchronous requests or not and includes username and password
void send()This method is used to send the request
void send (string)This method is used to send the request with POST method
setRequestHeader(header,value)This method is used to send the request with header values
abort() This method is used to abort the request
getAllResponseHeaders()This method returns the response header in the form of a string
getResponseHeader()This method returns the specific response header value

The abort() method of XMLHttpRequest is to be invoked to abort the current transaction

The ScriptManager provides the “IsInAsyncPostBack” property which can be used. The “IsInAsyncPostBack” property returns a Boolean value to check for partial page postbacks

The below given are the security drawbacks using AJAX

  1. AJAX source code is easy to read
  2. AJAX code can be inserted with the custom script by hackers

The below given are the common AJAX Frameworks

  1. Google Web Toolkit (GWT)
  2. JQuery
  3. Angular JS
  4. Backbone.js
  5. Ext JS

Cross-domain allows to transfer data between two or more security domains. The below given methods can be used for Cross -Domain AJAX calls

  1. Cross-Origin Resource Sharing (CROS) : This methods supports all HTTP Verbs and is supported by all web browsers
  2. JSON with padding (JSONP) : This methods supports only HTTP GET Verb and is not supported by all browsers

The below given are the main differences between JavaScript and AJAX

JavaScriptAJAX
JavaScript is a object based scripting languageAJAX uses XMLHttpRequest object for communicating with server and uses JavaScript, XML, HTML and CSS
JavaScript send and received data in synchronous wayAJAX sends the request and does not wait for the response supporting asynchronous transactions
JavaScript does not support partial page update AJAX supports partial page update

AsyncPostBackTimeout Property specifies the time (in seconds) within which the response is to be received from the server. If the specified time exceeds, then asynchronous postback timeout occurs

The default value for “AsyncPostBackTimeout” Property is 90 seconds

The below given are the ready states of a request in AJAX

0 means UNOPENED
1 means OPENED
2 means HEADERS_RECEIVED
3 means LOADING
4 means DONE

The process of retrieving near-live data regularly from a server is called AJAX polling

The below given are the main differences between Synchronous and Asynchronous Ajax requests

Synchronous AJAX Request Asynchronous AJAX Request
The request sent to the server waits for the response to complete the transaction
Blocks the JavaScript Engine until the request is completedDoes not block the JavaScript Engine
The page refresh happened whenever the request is submittedPartial page is updated with the received response and does not require page refresh
User need to wait until the request is processedUser can perform other tasks while the request is processed

The below given are the main differences between SPA and AJAX

SPA AJAX
SPA is single page application runs within the single web pageAJAX is used to communicate with server for processing the request
SPA is used to develop a standalone applicationAJAX is used to perform the back end communication for the received user request
SPA being a single page application does not communicate with different web pagesAJAX is used to transfer data among different web pages as per user action