Important Ajax Interview Questions
Q – 1 Do I really need to learn JavaScript before AJAX?
Ans- Basically yes if you plan to develop new AJAX functionality for your web application.
On the other hand, JSF components and component libraries can abstract the details of JavaScript, DOM and CSS. These components can generate the necessary artifacts to make AJAX interactions possible. Visual tools such as Java Studio Creator may also use AJAX enabled JSF components to create applications, shielding the tool developer from many of the details of AJAX.
If you plan to develop your own JSF components or wire the events of components together in a tool it is important that you have a basic understanding of JavaScript. There are client-side JavaScript libraries (discussed below) that you can call from your in page JavaScript that abstract browser differences. Object Hierarchy and Inheritance in JavaScript is a great resource for a Java developer to learn about JavaScript objects.
Q – 2 Do Ajax applications always deliver a better experience than traditional web applications?
Ans- Not necessarily. Ajax gives interaction designers more flexibility. However, the more power we have, the more caution we must use in exercising it. We must be careful to use Ajax to enhance the user experience of our applications, not degrade it.
Q – 3 Are Ajax applications easier to develop than traditional web applications?
Ans- Not necessarily. Ajax applications inevitably involve running complex JavaScript code on the client. Making that complex code efficient and bug-free is not a task to be taken lightly, and better development tools and frameworks will be needed to help us meet that challenge.
Q – 4 Did Adaptive Path invent Ajax? Did Google? Did Adaptive Path help build Google’s Ajax applications?
Ans- Neither Adaptive Path nor Google invented Ajax. Google’s recent products are simply the highest-profile examples of Ajax applications. Adaptive Path was not involved in the development of Google’s Ajax applications, but we have been doing Ajax work for some of our other clients.
Q – 5 Cannot parse XML generated by JSP I am generating an XML using JSP, when I run the JSP in IE it shows the XML as per DOM, but when I try to parse it using Javascript , the command xmldoc.documentElement?
Ans- This is working code, it might help you.
if (!isIE)
xmldoc = req.responseXML;
else
{
//IE does not take the responseXML as.
Q – 6 Can I use Ajax with Microsoft’s .NET?
Ans- See http://ajax.schwarz-interactive.de/ for a free AJAX implementation for the .NET Framework
Q – 7 Are there Usability Issues with AJAX?
Ans- The nature of updating a page dynamically using data retrieved via AJAX interactions and DHTML may result in drastically changing the appearance and state of a page.
A user might choose to use the browser’s back or forward buttons, bookmark a page, copy the URL from the URL bar and share it with a friend via an email or chat client, or print a page at any given time. When designing an AJAX based application you need to consider what the expected behavior would be in the case of navigation, bookmarking, printing, and browser support as described below.
* Navigation – What would be the expected behavior of the back, forward, refresh, and bookmark browser buttons in your application design. While you could implement history manipulation manually it may be easer to use a JavaScript frameworks such as Dojo that provides API’s history manipulation and navigation control.
* Bookmarking and URL sharing – Many users want to bookmark or cut and paste the URL from the browser bar. Dojo provides client-side for bookmarking and URL manipulation.
* Printing – In some cases printing dynamically rendered pages can be problematic.
Other considerations as a developer when using AJAX are:
* Browser Support – Not all AJAX/DHTML features are supported on all browsers or all versions of a browser. See quirksmode.org for a list of browser support and possible workarounds.
Q – 8 Are there any security issues with AJAX?
Ans- JavaScript is in plain view to the user with by selecting view source of the page. JavaScript can not access the local file system without the user’s permission. An AJAX interaction can only be made with the servers-side component from which the page was loaded. A proxy pattern could be used for AJAX interactions with external services.
You need to be careful not to expose your application model in such as way that your server-side components are at risk if a nefarious user to reverse engineer your application. As with any other web application, consider using HTTPS to secure the connection when confidential information is being exchanged.
Q – 9 Are there any frameworks available to help speedup development with AJAX?
Ans- are several browser-side frameworks available, each with their own uniqueness
Q – 10 Does this mean Adaptive Path is anti-Flash?
Ans- Not at all. Macromedia is an Adaptive Path client, and we’ve long been supporters of Flash technology. As Ajax matures, we expect that sometimes Ajax will be the better solution to a particular problem, and sometimes Flash will be the better solution. We’re also interested in exploring ways the technologies can be mixed (as in the case of Flicker, which uses both).
Q – 11 Does Java have support for Comet style server-side push?
Ans- Current AJAX applications use polling to communicate changes data between the server and client. Some applications, such as chat applications, stock tickers, or score boards require more immediate notifications of updates to the client. Comet is an event based low latency server side push for AJAX applications.
Comet communication keeps one of the two connections available to the browser open to continously communicate events from the server to the client. A Java based solution for Comet is being developed for Glassfish on top of the Grizzly HTTP connector. See Enabling Grizzly by Jean-Francois Arcand for more details.
Q – 12 Does AJAX work with Java?
Ans- Absolutely. Java is a great fit for AJAX! You can use Java Enterprise Edition servers to generate AJAX client pages and to serve incoming AJAX requests, manage server side state for AJAX clients, and connect AJAX clients to your enterprise resources. The JavaServer Faces component model is a great fit for defining and using AJAX components.
Q – 13 Does Ajax have significant accessibility or browser compatibility limitations?
Ans- Does Ajax have significant accessibility or browser compatibility limitations? Do Ajax applications break the back button? Is Ajax compatible with REST? Are there security considerations with Ajax development? Can Ajax applications be made to work for users who have JavaScript turned off?
The answer to all of these questions is “maybe”. Many developers are already working on ways to address these concerns. We think there’s more work to be done to determine all the limitations of Ajax, and we expect the Ajax development community to uncover more issues like these along the way.
Q – 14 Techniques for asynchronous server communication have been around for years. What makes Ajax a “new” approach?
Ans- What’s new is the prominent use of these techniques in real-world applications to change the fundamental interaction model of the Web. Ajax is taking hold now because these technologies and the industry’s understanding of how to deploy them most effectively have taken time to develop.
Q – 15 Some of the Google examples you cite don’t use XML at all. Do I have to use XML and/or XSLT in an Ajax application?
Ans- No. XML is the most fully-developed means of getting data in and out of an Ajax client, but there’s no reason you couldn’t accomplish the same effects using a technology like JavaScript Object Notation or any similar means of structuring data for interchange.
Mashup is a popular term for creating a completely new web application by combining the content from disparate Web Services and other online API’s. A good example of a mashup is housingmaps.com which graphically combines housing want-ads from craiglist.org and maps from maps.google.com.
Q – 16 Should I use XML or text, JavaScript, or HTML as a return type?
Ans- It depends. Clearly the ‘X’ in AJAX stands for XML, but several AJAX proponents are quick to point out that nothing in AJAX, per se, precludes using other types of payload, such as, JavaScript, HTML, or plain text.
* XML – Web Services and AJAX seem made for one another. You can use client-side API’s for downloading and parsing the XML content from RESTful Web Services. (However be mindful with some SOAP based Web Services architectures the payloads can get quite large and complex, and therefore may be inappropriate with AJAX techniqes.)
* Plain Text – In this case server-generated text may be injected into a document or evaluated by client-side logic.
* JavaScript – This is an extension to the plain text case with the exception that a server-side component passes a fragment of JavaScript including JavaScript object declarations. Using the JavaScript eval() function you can then create the objects on the client. JavaScript Object Notation (JSON), which is a JavaScript object based data exchange specification, relies on this technique.
* HTML – Injecting server-generated HTML fragments directly into a document is generally a very effective AJAX technique. However, it can be complicated keeping the server-side component in sync with what is displayed on the client.
Mashup is a popular term for creating a completely new web application by combining the content from disparate Web Services and other online API’
Q – 17 Should I use an HTTP GET or POST for my AJAX calls?
Ans- AJAX requests should use an HTTP GET request when retrieving data where the data will not change for a given request URL. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture.
Q – 18 Should I consider AJAX?
Ans- AJAX definitely has the buzz right now, but it might not be the right thing for you. AJAX is limited to the latest browsers, exposes browser compatibility issues, and requires new skill-sets for many. There is a good blog entry by Alex Bosworth on AJAX Mistakes which is a good read before you jump full force into AJAX.
On the other hand you can achieve highly interactive rich web applications that are responsive and appear really fast. While it is debatable as to whether an AJAX based application is really faster, the user feels a sense of immediacy because they are given active feedback while data is exchanged in the background.
If you are an early adopter and can handle the browser compatibility issues, and are willing to learn some more skills, then AJAX is for you. It may be prudent to start off AJAX-ifying a small portion or component of your application first. We all love technology, but just remember the purpose of AJAX is to enhance your user’s experience and not hinder
Q – 19 Is the XMLHttpRequest object part of a W3C standard?
Ans- No. Or not yet. It is part of the DOM Level 3 Load and Save Specification proposal.
Q – 20 Is the server or the client in control in AJAX?
Ans- It depends. With AJAX the answer is more in between. Control can be more centralized in a server-side component or as a mix of client-side and server-side controllers.
* Centralized server-side controller – When having a more centralized controller the key is to make sure the data in client-side page is in sync with that of the server. Some applications may keep all the state on the server and push all updates to client DOM via a simple JavaScript controller.
* Client and server-side controllers – This architecture would use JavaScript to do all presentation related control, event processing, page manipulation, and rendering of model data on the client. The server-side would be responsible for things such as business logic and pushing updated model data to the client. In this case the server would not have intimate knowledge of the presentation short of the initial page that would be sent to the client page request.
There are some use cases where an entire AJAX application can be written in a single page. Keep in mind if you choose this type of architecture that navigation and bookmarking should be considered.
Both methods are viable depending on what you are trying to accomplish. I tend to prefer spreading the control across the client and server.
Q – 21 Is it possible to set session variables from JavaScript?
Ans- It’s not possible to set any session variables directly from JavaScript as it is purely a client side technology. You can use AJAX though to asyncronously…
Q – 22 How do I handle the back and forward buttons in AJAX?
Ans- While you could go out and create a custom solution that tracks the current state on your application I recommend you leave this to the experts. Dojo addresses the navigation in a browser neutral way as can be seen in the JavaScript example below.
function updateOnServer(oldId, oldValue,
itemId, itemValue) {
var bindArgs = {
url: “faces/ajax-dlabel-update”,
method: “post”,
content: {“component-id”: itemId, “component-value”:
itemValue},
mimetype: “text/xml”,
load: function(type, data) {
processUpdateResponse(data);
},
backButton: function() {
alert(“old itemid was ” + oldId);
},
forwardButton: function(){
alert(“forward we must go!”);
}
};
dojo.io.bind(bindArgs);
}
The example above will update a value on the server using dojo.io.bind() with a function as a property that is responsible for dealing with the browser back button event. As a developer you are capable of restoring the value to the oldValue or taking any other action that you see fit.
Q – 23 How does HTML_AJAX compare with the XAJAX project at Sourceforge?
Ans- XAJAX uses XML as a transport for data between the webpage and server, and you don’t write your own javascript data handlers to manipulate the data received from the server. Instead you use a php class and built in javascript methods, a combination that works very similiar to the HTML_AJAX_Action class and haSerializer combo. XAJAX is designed for simplicity and ease of use.
HTML_AJAX allows for multiple transmission types for your ajax data – such as urlencoding, json, phpserialized, plain text, with others planned, and has a system you can use to write your own serializers to meet your specific needs. HTML_AJAX has a class to help generate javascript (HTML_AJAX_Helper) similiar to ruby on rail’s javascript helper (although it isn’t complete), and an action system similiar to XAJAX’s “action pump” that allows you to avoid writing javascript data handlers if you desire.
But it also has the ability to write your own data handling routines, automatically register classes and methods using a server “proxy” script, do different types of callbacks including grabbing remote urls, choose between sync and async requests, has iframe xmlhttprequest emulation fallback capabilities for users with old browsers or disabled activeX, and is in active development with more features planned (see the Road Map for details)
Q – 24 How do I submit a form or a part of a form without a page refresh?
Ans- When creating a form make sure that the “form” element “onSubmit” attribute is set to a JavaScript function that returns false.