Google News
logo
Ajax Interview Questions
AJAX stands for Asynchronous JavaScript and XML.It is the use of the  XMLHttpRequest object to communicate with servers. The Ajax was publicly used on 18 February 2005 by Jesse James Garrett. Mainly we are creating interactive web applications. 
Following are the advantages of Ajax :

Quick Response
Bandwidth utilization -  It saves memory when the data is fetched from the same page.
User is not blocked until data is retrieved from the server.
More interactive
Following are the disadvantages of Ajax :

Dependent on JavaScript
Source code written in AJAX is easily human readable. There will be some security issues in Ajax.
Debugging is difficult
Increases size of the requests
Slow and unreliable network connection.
AJAX uses following technologies :

JavaScript
XMLHttpRequest
Document Object Model (DOM)
Extensible HTML (XHTML)
Cascading Style Sheets (CSS)
sends data in the background
receives data
updates data without reloading the page
The important properties of XMLHttpRequest object are given below.

onReadyStateChange
readyState
responseText
responseXML
Users cannot use AJAX if

If Page need to show in a search engine
If browser does not support JavaScript
If user wants to create secure application
Following are the features of Ajax and they are as follows :

Live data binding
Client-side template rendering
Declarative instantiation of client components
Observer pattern on JavaScript objects and arrays
Invoking ADO.NET data services and data contexts
DataView control
JSON is abbreviated as JavaScript Object Notation.

JSON is a safe and reliable data interchange format in JavaScript, which is easy to understand for both users and machines.
Internet Explorer 7.0 and above
Google Crome 36.0 and above
Opera 7.6 and above
Netscape 7.1 and above
Safari 1.2 and above
Two tools are used for debugging :
 
Fiddler for IE
Firebug for Mozilla.
Following syntax can be used to create Ajax objects :

var sample = new ajaxObject(‘path of the page’)
HTTP’s GET or POST
XMLHttpRequest for placing a request with the web server
Uses JSON to communicate between the client and server
UED or URL encoded data

The differences between AJAX and JavaScript are given as follows :

AJAX sends request to the server and will not wait for the response.
It will allow other operations on the page before it get response of previous request; whereas, JavaScript make a request to the server, will waits for response and 

will not allow other operation on the page during that time.
In AJAX, the page will not get refreshed for downloading the whole page while JavaScript manages and controls a Web page after being downloaded.
By using AJAX we can minimize the overload on the server because the script needs to request once while JavaScript posts the request that updates the script each time.
The server-side framework facilitates the developers to develop Ajax functionality, without gaining much knowledge of JavaScript.
This framework supports server controls and components as well as the drag and drop features.
This framework is usually preferred when you required to rapidly ajaxify an asp.net web page. The drawback is that a round trip will take place to the server to 

execute a client-side action.
The Client-Side Framework allows you to build web applications with rich user-interactivity as that of a desktop application.
It includes a set of JavaScript libraries, which is not dependent from ASP.NET. The functionalities of this library are enhanced in every release.
We can use GET OR POST Method to send data.
AJAX requests should use an HTTP GET request where the data does not change for a given URL requested.

An HTTP POST should be used when state is updated on the server. This is highly recommended for a consistent web application architecture.
Cross-domain means the ability to manually or automatically access or transfer data between two or more differing security domains.
Cross-Origin Resource Sharing (CROS) : Works with all HTTP verbs and most modern web browsers. Provides better support for error handling than JSONP.
JSON with padding (JSONP) : It only works with HTTP GET verb and on legacy browsers.
User send request from a browser where JavaScript is enabled. XMLHttpRequest object receives call and sent it to server. Server retrieves data and sends XML or JSON data back to HMLHttpRequest callback function and data is shown to user on browser.
Ajax has following core controls.
 
* UpdatePanel
* UpdateProgress
* ScriptManager
* ScriptManagerProxy
* Timer control
UpdatePanel allows rendering partial page. You can refresh important parts of the page instead of refreshing whole page.
UpdateProgress control  shows the progress for all partial-page updates on the page. You can use an UpdatePanel control for every UpdateProgress control.
There is only one ScriptManager control in one page. It registers ajax library scripts for that page. It also creates proxies for asynchronous web service call.
As mentioned above there is only one ScriptManager control in one page but the page can have multiple ScriptManagerProxy controls. If you have the ScriptManager in master page which will go across all pages, you cannot add another ScriptManager to underlying pages, instead ScriptManagerProxy control would be added to those underlying pages otherwise the page would show error.
MooTools : It is one of the popular JavaScript toolkits which is primarily used for creating visual effects.

Google Web Toolkit (GWT) : It enables developers to create rich Ajax applications using Java.

Dojo Toolkit : It is most popular toolkit and used in large number of applications. It is a modular JavaScript toolkit which is distributed under an open-source license. Dojo toolkit includes many user interface effects, widget APIs, drag and drop AISs etc.

Yahoo User Interface(YUI) :  YUI library is an open source JavaScript framework and is used to make interactive applications.

Spry : This framework was developed by Adobe. It consists of animation and visual effects components, a data binding component, and a framework to crate widgets.
It is a web application which has many characteristics of desktop application software. It has quick response time and many advanced functions. An RIA is browser dependent or require browser plugin or a virtual machine to deliver user application.
In AJAX, the readyState is a function to be called when the readyState property changes. It holds the status of the XMLHttpRequest.
The different types of real-time applications include security authentications which can be applied for the AJAX web applications on the server side and client side as well. XML in AJAX is least used whereas the JSON is the most used data format for the exchange of information across different sources. AJAX also provides the feature of fetching resources using Fetch API of XMLHTTPRequest object.
JavaScript closures are used to handle such synchronous requests. Firstly functions are built and then parameters (back function and URL) to corresponding functions are selected with the use of Closures and pass to AJAX URL Objects.
Proxied : calls are made through stub objects which can be called from PHP classes on the JavaScript side in AJAX.
 
Proxyless : calls are made using utility JavaScript functions like HTML_AJAX.replace() and HTML_AJAX.append() in AJAX.
Following are the functions :
 
RegisterClientScriptBlock : The script is specified as a string parameter.

RegisterClientScriptInclude : By setting the source attribute to a URL that point to a script file.

RegisterClientScriptResource : specifies Resource name in an assembly. The source attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.
The following are the limitations of AJAX :
 
It is difficult to bookmark a particular state of the application
 
Function provided in the code-behind file do not work because the dynamic pages cannot register themselves on browsers history engine automatically
 
If JavaScript is disabled, then AJAX is not able to perform any work
 
Response time may be slow because different controls of a page are loaded at different time.