Tuesday, August 19, 2014

AJAX

Ajax interview

1) What is AJAX?
2) When do I use a synchronous versus a synchronous request?
3) When should I use java applet instead of Ajax?
4) What browsers supports AJAX?
5)  What do I do on the server to interact with the Ajax client?
6). What is difference between proxied and proxy less calls in AJAX?
7).  What is XMLHttpRequest object in AJAX?
8). What JavaScript libraries and frameworks are available for AJAX support? 
9).  How Ajax is different?
10). How do we abort the current XMLHttpRequest in AJAX?
11).    Is Ajax a technology platform or is it an architectural style?
12)   Is Ajax just another name for XMLHttpRequest?
13).   How do I test my Ajax code?
14). How do I submit form or part of form without page refresh?
15).  Is it possible to set session variables from JavaScript?
16).   Is the server or client in control in Ajax?
17).   Should I use an HTTP GET or POST for my AJAX calls?
18).   Are there usability issues with Ajax?
19).  Are Ajax applications easier to develop than traditional web applications?
20). Do Ajax applications always deliver better experience than traditional web applications?

What is AJAX?

- Ajax stands for asynchronous JavaScript and XML
- XMLHttpRequest object is used to exchange data asynchronously with the web server.
- in some Ajax frameworks and in some situations, an IFrame object is used instead of XMLHttpRequest object to exchange data with the web server.
- Ajax is not a technology itself, but term that refers to the use of group of technologies together

When do I use a synchronous versus a synchronous request?

- a synchronous request would block in page event processing and I don't see many use cases where a synchronous request is preferable.

When should I use java applet instead of Ajax?

- reason Ajax is so popular is that it only requires functionality built into the browser(namely DHTML and Ajax capabilities).
- user does not need to configure or download plugins.
- it is easy to incrementally update functionality and know that functionality will readily available and there are not any complicated deployment issues.

What browsers supports AJAX?

- IE 5.0 and up
- Opera 7.6 and up
- Netscape 7.1 and up
- firefox 1.0 and up
- safari 1.2 and up

What do I do on the server to interact with the Ajax client?

- the content type header needs to be set to "text/XML".
- in servlets this may be done using the HttpServletResponse.setContentType() be set to "text/XML" when the return type is XML.
Response.setcontentType("text/XML");
Response.getWriter().write("<response>invalid</response>")

What is difference between proxied and proxy less calls in AJAX?

- proxied calls are made throu stub objects that mimic your PHP classes on JavaScript side in AJAX. Ex: hello world class from hello world example
- proxy less calls are made using utility javascript functions like HTML_AJAX.replace() and HTML_AJAX.append in AJAX

What is XMLHttpRequest object in AJAX?

- it offers a non blocking  way for JavaScript to communicate back to the web server to update only part of web page.

What JavaScript libraries and frameworks are available for AJAX support?

- three good libraries are Dojo toolkit, Prototype and DWR.

- dojo toolkit contains APIs and widgets to support development of rich web applications.
- dojo contains an intelligent packaging system, ui effects, drag and drop APIs, widget Apis, event abstraction and AJAX interaction APIs.
- dojo solves common usability issues such as support for dealing with with navigation such as ability to detect browser back button, ability to support changes to the URL in the URL bar for bookmarking and ability to gracefully degrade when AJAX/JavaScript is not fully support on client.
- it does a very good job supporting new and older browsers.

How Ajax is different?

- an Ajax application eliminates the start-stop-start-stop nature of interaction on the web by introducing an intermediary- an AJAX engine between the user and server.
- instead of loading a webpage, at the start of the session, the browser loads an Ajax engine- written in JavaScript and usually tucked away in a hidden frame.
- this engine is responsible for both rendering the interface the user sees and communicating with the server on the users behalf.
- Ajax engine allows the users interaction with the application to happen asynchronously- independent of communication with the server.

How do we abort the current XMLHttpRequest in AJAX?

- just call the abort() method on the request to abort the current XMLHttpRequest in AJAX.

Is Ajax a technology platform or is it an architectural style?

- both. Ajax is set of technologies being used together in a particular way.

Is Ajax just another name for XMLHttpRequest?

- no. XMLHttpRequest is only part of the Ajax equation.
- XMLHttpRequest is technical component that makes the asynchronous server communication possible.
- Ajax is our name for overall approach described in article, which relies not on XMLHttpRequest, but on CSS, DOM and other technologies.

How do I test my Ajax code?

- there is a port of JUnit for client side JavaScript called jsunit used to test AJAX code.


- while it may appear that images are sent when using Ajax with an application like google maps what is really happening is that the URLs of images are being sent as response of an AJAX request and those URLs are being set using DHTML.

How do I submit form or part of form without page refresh?

- when creating form make sure that the form element onSumit attribute is set to a JavaScript function that returns false.
<form onSubmit="doAjaxSubmit(); return false;">
<input type ="text" I'd="tf1"/>
<input type="submit" I'd="submit1" value="update"/>
</>

Is it possible to set session variables from JavaScript?

- it's not possible to set session variables directly from JavaScript as it is purely client side technology.
- you can use Ajax though to asynchronously.

Is the server or client in control in Ajax?

- it depends. With Ajax answer is more in between.
- control can be more centralized in server side component or as a mix of client side and server side controllers.
- centralized server side controller: make sure data in client side is in sync with server side.
- client and server side controller: this architecture would use JavaScript to do all presentation related control, event processing, page manipulation and rendering of model data on client.

Should I use an HTTP GET or POST for my AJAX calls?

- 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.

Are there usability issues with Ajax?

- when designing an Ajax based application you need to consider what the expected behavior would be in case of navigation, bookmarking, printing, and browser support 
- navigation: what would be expected behavior of back, forward, refresh and bookmark browser buttons in your application design.
- bookmarking and URL sharing: many users want to bookmark or cut and paste URL from the browser bar. dojo provides client side for bookmarking and URL manipulation.
- browser support: not all AJAX/DHTML features are supported on all browsers or all versions of a browser.

Are Ajax applications easier to develop than traditional web applications?

- 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.

Do Ajax applications always deliver better experience than traditional web applications?

- not necessarily. Ajax gives interaction designer more flexibility.
- however 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.

No comments:

Post a Comment