Ajax interview questions for experience - contributed by Arpit
Jain
1) Which are limitations
of AJAX?
2) What is the difference
between synchronous postback and asynchronous postback?
3) Why do we use the
XMLHttpRequest object in AJAX?
4) What are the new
features included in the Microsoft AJAX library?
5) What are the new
features of ASP.NET AJAX 4.0?
6) How many validation
controls are supported in ASP.NET AJAX 4.0?
7) What are the
differences between AJAX and JavaScript?
8) List the different
states of XMLHttpRequest with their description.
9) Describe the
AccordionExtender control.
10) How do I provide
internationalized AJAX interactions?
11) How do I submit a
form or a part of a form without a page refresh?
12) How do I create a
thread to do AJAX polling?
13) Describe the formats
and protocols used by AJAX
14) Are there security
issues with AJAX?
15) What are Difference
between Server-Side AJAX framework and Client-side AJAX framework?
16) If there is an input
in the text field what are all the functions which get executed?
17) What is an
UpdatePanel Control?
18) How does one call a
JavaScript function from the AJAX code?
19) Which is the purpose
for using the ScriptManager?
20) Which are the major
ASP.NET Ajax Server Controls?
1) Which are limitations of AJAX?
-
Back functionality can’t work because the dynamic pages won’t register
themselves to the browsers cache. Hence the use Iframe will become required.
-
The page cannot be bookmarked if it is developed using Ajax.
-
If java script is not enabled, Ajax will stop working.
-
Because different components of the pages are loaded at different times,
response time may be slow.
-
Because different components of the pages are loaded at different times it may
create confusion for the user.
2) What is the difference between synchronous postback and asynchronous
postback?
The difference between synchronous and asynchronous postback is as follows:
-
Asynchronous postback renders only the part of the page which is needed; while,
synchronous postback renders the entire page in a postback.
-
Asynchronous postback executes only one postback at a time, that is, if you
have two buttons doing asynchronous postback, the actions are executed one by
one; while, synchronous postback invoke all the actions at a time.
-
Asynchronous postback only changes the update panel that invoke the postback;
while, synchronous postback changes the entire page.
3) Why do we use the XMLHttpRequest object in AJAX?
-
Javascript uses the XMLHttpRequest object to manipulate XML and other text data
between client and server.
-
AJAX applications use the XMLHttpRequest object to avoid the postback of entire
page when the browser is communicating with server.
-
The XMLHttpRequest object enables a client-side script to execute an HTTP
request.
-
For this functionality MSXML ActiveX component is used in earlier version of
Internet Explorer. While, XMLHttpRequest is used in Internet Explorer 7 and
other browsers, such as Mozilla, Firefox.
4) What are the new features included in the Microsoft AJAX library?
The new features included in the Microsoft AJAX library are as follows:
-
Imperative syntax: AJAX library provide simple imperative syntax which is
required to create and manage controls.
-
Script loader: It is used to retrieve all scripts automatically which are
required by one or more client component or control and executes them in the
order in which they are received.
-
Client data access: It’s used to access client data and display by client data
control and client template.
-
Client datacontext: It’s used to read and write the permission to data in a
database.
-
The AdoNetDataContext class - Supports to easily communicate to an ADO.NET Data
Services service.
5) What are the new features of ASP.NET AJAX 4.0?
These features are as follows:
-
It enables the application to bind the live data.
-
It enables to render the client-side template.
-
It enables declarative instantiation of client components.
-
It provides observer pattern on JavaScript objects and arrays.
-
It provides the facility to invoke ADO.NET data services and data contexts.
-
It supports for the DataView control.
6) How many validation controls are supported in ASP.NET AJAX 4.0?
The following validation controls are supported in ASP.NET AJAX 4.0:
-
FilteredTextBoxExtender : This validation is used to apply filtering to a text
box.
-
MaskedEditExtender and MaskedEditValidator : These validation controls are used
to prevent a user to enter only a particular pattern of characters in the
TextBox.
-
ValidatorCalloutExtender : This validation is used to display a balloon tooltip
containing the error message by attaching the ASP.NET validators.
-
NoBot : It restricts the input forms automatically to be filled by spam/bot and
used to ensure that the user is not a computer machine by the automated Public
Turing test.
-
PasswordStrengthExtender : It is used to find the strength of the password
entered in the text box by checking the different strength related parameters.
7) What are the differences between AJAX and JavaScript?
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.
8) List the different states of XMLHttpRequest with their description.
The different states of the XMLHttpRequest object are as follows:
-
1) Uninitialized : It is the state in which the object has not been
initialized.
-
2) Open: It is the state when the object has been created but the send function
is not invoked.
-
3) Sent: It is the state when the send function is invoked but the status and
headers are not available.
-
4) Receiving: It is the state when the data is received by the process.
-
5) Loaded: It is the state when the procedure is completed and the data is
available.
9) Describe the AccordionExtender control.
-
The AccordionExtender control is almost same as the CollapsiblePanelExtender
control.
-
It enables the grouping of multiple collapsible panels in a single control.
-
It also manages the collapsed and expanded state of every panel and one panel
will expand at a time.
-
Using AccordionExtender control we can’t expand two or more panels at a time.
However, we can click the header templates of particular panel to display the
hidden contents.
-
By default, one panel is always expanded in theAccordionExtender.
10) How do I provide internationalized AJAX interactions?
To provide internationalized AJAX components you need to do the following:
-
Set the charset of a page to an encoding which is provided by the target
languages. The following meta declaration in your HTML/JSP page is used to set
the content type:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
In the page JavaScript ensure that the encoding of any parameters sent to the
server is done. To achieve this JavaScript has the escape() function which will
give Unicode escape strings containing localized text in hexadecimal format.
-
In the server side component set the character encoding using the
HttpServletRequest.setCharacterEncoding() method. Before accessing the
localized parameter with HttpServletRequest.getParameter() call. In the case of
UTF this will be request.setCharactherEncoding("UTF-8");.
-
A server-side component returning AJAX responses requires to set the encoding
of the response to the similar encoding used in the page.
response.setContentType("text/xml;charset=;UTF-8");
response.getWriter().write(" <response>Not valid </response>");
11) How do I submit a form or a part of a form without a page refresh?
-
When creating a form ensure that in the "form" element "onSubmit" attribute
calls the JavaScript function that returns false.
<form onSubmit="doSubmit();return false;" >
<input type="text" id="myinput" /><input type="submit" id="btnSubmit"
value="Save"/>
</>
o The other way is to associate a function with a form button in a similar way.
<form onSubmit="doSubmit();return false;" >
<input type="text" id="myinput" />
<input type="button" id="button1" onClick="doSubmit()" value="Save"/>
</>
While you update the page it is recommended that you should wait to confirm
that the AJAX update of the form data was successful before updating the data
in your page. Otherwise, it is possible that the data is not updated properly
and the user is not aware about it. It is suggested to display a loading
message message when doing a partial update and after the successful AJAX
interaction we can update the page.
12) How do I create a thread to do AJAX polling?
-
JavaScript does not provide threads. JavaScript functions are called after an
event occurred on a page like the page is loaded, a mouse click, or a form
element get focused.
-
You can make a timer by using the setTimeout which requires a function name and
time in milliseconds as its arguments.
-
Calling the same function using loop which is given in the JavaScript example
below.
function checkForMsg() {
// start AJAX interaction with handleCallback as the callback function
}
// callback for the request
function handleCallback() {
// do post processing
setTimeout("checkForMsg()", 20000);
}
Note that the checkForMessage will continue to loop infinitely. You may want to
change the increment interval based on activity. You may also want to change
the logic which will break the loop based on some AJAX response executing
condition.
13) Describe the formats and protocols used by AJAX
-
The client web page is creates the XmlHttpRequest, and thus the connection from
the web page to an application on the server.
-
Part of that connection determines how the response can be produced to the
client code – via the use of a “callback” routine.
-
The callback routine is called multiple times which come with a status code
which indicates the reason for the invocation.
-
When a request can be successfully completed by the server application, a
response should also be produced.
14) Are there security issues with AJAX?
-
JavaScript is in plain view to the user with by selecting view source of the
page. JavaScript cannot access the local file system without the user's
permission.
-
An AJAX interaction can only be achieved with the servers-side component from
which the page is loaded.
-
A proxy pattern can be used for AJAX interactions with external services.
-
We should take care that the application model is not exposed in such a way
that our server-side components are at risk if a user to reverse engineer your
application.
-
Like any other web application we should use HTTPS to secure the connection
when sensitive information is being exchanged.
15) What are Difference between Server-Side AJAX framework and
Client-side AJAX framework?
-
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.
16) If there is an input in the text field what are all the functions
which get executed?
We can execute following functions when there is an input in the text field.
-
1) Defines the url that we will sent to the server
-
2) A parameter is inserted to the input field’s content.
-
3) A parameter is inserted to restrict the server from the cache.
-
4) When a change is triggered statechange is invoked.
-
5) An XMLHTTP object having a given URL gets invoked
-
6) A request is sent to the server through HTTP.
17) What is an UpdatePanel Control?
-
An UpdatePanel control is a cover for server side controls which is to be
partial postbacked on ajax enabled page.
-
All controls included in the UpdatePanel will be partial postbacked. Below is a
small example of using an UpdatePanel.
<asp:ScriptManager runat=”server”>
</ asp:ScriptManager>
<asp:UpdatePanel runat=”server”>
<ContentTemplate>
<asp:Button runat=”server”></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
-
On clicking the button the page will be updated partially. There won’t be a
full postback by the web page.
-
In this way the content beyond the update panel won’t be posted back to the
server.
-
The contents in the updatepanel will be refreshed only.
18) How does one call a JavaScript function from the AJAX code?
-
Ajax is a form of JavaScript, which uses XML Http Request objects which pass
action event parameters to a method named “open”.
-
In AJAX we can’t track the requests and responses in any order.
-
”XMLHttpRequest.open” is the function which uses action events as Parameters in
URL.
-
While “XMLHttp Request.send” sends the Request object either synchronously or
asynchronously which depend on whether the option for the synchronous version
is true or false?
19) Which is the purpose for using the ScriptManager?
The purposes of ScriptManager in ASP.NET AJAX are explained as following.
-
It enables the Client-script functionality of the Microsoft AJAX Library and it
also supports a custom script that we can send to the browser.
-
It supports Partial-page rendering, which enable us to make partial page update
without a postback.
-
The ASP.NET AJAX UpdatePanel, Timer and UpdateProgress controls work with
ScriptManager control to support partial-page rendering.
-
It supports JavaScript proxy classes for Web services that provide client
script which enable us to access Web services by exposing them as strongly
typed objects.
-
It provides JavaScript classes to deal with ASP.NET authentication and profile
application services.
20) Which are the major ASP.NET Ajax Server Controls?
-
Timer: This control is used to refresh the contents of a web page at already
specified intervals of time.
-
Script Manager: This is the heart of an AJAX enabled web page. To develop the
partial page rendering, it is necessary to set the EnablePartialRendering
property of the ScriptManager control to true.
-
ScriptManagerProxy: A ScriptManagerProxy control passes references to a
ScriptManager control in a master page to declare the Ajax behavior.
-
UpdateProgress: This control is required to display the progress when an update
action in partial page rendering process is in progress.
-
UpdatePanel :– Update panel is required to create partial page updates in an
Ajax enabled web page. All the controls which we need to involve in partial
page update we need to include them inside an UpdatePanel
control.
|