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
- AJAX helps in developing fast and interactive web pages
- AJAX does not depend on server technology
- AJAX based requests uses less server bandwidth
- AJAX makes form validation simple
The below given are the disadvantages of AJAX
- AJAX is not supported by all browsers
- AJAX code is easy to read
- 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:
- Send the request to the server without reloading the page
- Receives and update the data received as server response
- 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 |
readyState | 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 | returns the response in Text File Format |
responseXML | returns the response in XML Format |
status | returns the request status number |
statusText | returns 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
- AJAX source code is easy to read
- AJAX code can be inserted with the custom script by hackers
The below given are the common AJAX Frameworks
- Google Web Toolkit (GWT)
- JQuery
- Angular JS
- Backbone.js
- 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
- Cross-Origin Resource Sharing (CROS) : This methods supports all HTTP Verbs and is supported by all web browsers
- 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
JavaScript | AJAX |
---|---|
JavaScript is a object based scripting language | AJAX uses XMLHttpRequest object for communicating with server and uses JavaScript, XML, HTML and CSS |
JavaScript send and received data in synchronous way | AJAX 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 completed | Does not block the JavaScript Engine |
The page refresh happened whenever the request is submitted | Partial page is updated with the received response and does not require page refresh |
User need to wait until the request is processed | User 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 page | AJAX is used to communicate with server for processing the request |
SPA is used to develop a standalone application | AJAX 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 pages | AJAX is used to transfer data among different web pages as per user action |