Ajax Interview Questions

Did Adaptive Path invent Ajax? Did Google? Did Adaptive Path help build Google’s Ajax applications?

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.

Is it possible to set session variables from javascript?

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.

What do I need to know to create my own AJAX functionality?

If you plan not to reuse and existing AJAX component here are some of the things you will need to know.

Plan to learn Dynamic HTML (DHTML), the technology that is the foundation for AJAX. DHTML enables browser-base realtime interaction between a user and a web page. DHTML is the combination of JavaScript, the Document Object Model (DOM) and Cascading Style Sheets (CSS).

* JavaScript – JavaScript is a loosely typed object based scripting language supported by all major browsers and essential for AJAX interactions. JavaScript in a page is called when an event in a page occurs such as a page load, a mouse click, or a key press in a form element.

* DOM – An API for accessing and manipulating structured documents. In most cases DOM represent the structure of XML and HTML documents.

* CSS – Allows you to define the presentation of a page such as fonts, colors, sizes, and positioning. CSS allow for a clear separation of the presentation from the content and may be changed programmatically by JavaScript.

Understanding the basic request/response nature of HTTP is also important. Many subtle bugs can result if you ignore the differences between the GET and POST methods when configuring an XMLHttpRequest and HTTP response codes when processing callbacks.

JavaScript is the client-side glue, in a sense. JavaScript is used to create the XMLHttpRequest Object and trigger the asynchronous call. JavaScript is used to parse the returned content. JavaScript is used to analyze the returned data and process returned messages. JavaScript is used to inject the new content into the HTML using the DOM API and to modify the CSS.

Is Ajax just another name for XMLHttpRequest?

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

Can Ajax be used with Microsoft’s .NET?

See http://ajax.schwarz-interactive.de/ for a free AJAX implementation for the .NET Framework.

Can we use HTTP GET or POST for 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. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture.

How can you submit a form or a part of a form without a page refresh?

When creating a form make sure that the “form” element “onSubmit” attribute is set to a JavaScript function that returns false.

<form onSubmit=”doAJAXSubmit();return false;” >

<input type=”text” id=”tf1″ />

<input type=”submit” id=”submit1″ value=”Update”/>

</>

You can also submit data by associating a function with a form button in a similar way.

<form onSubmit=”doAJAXSubmit();return false;” >

<input type=”text” id=”tf1″ />

<input type=”button” id=”button1″ onClick=”doAJAXSubmit()” value=”Update”/>

</>

Note that the form “onSubmit” attribute is still set. If the user hits the enter key in the text field the form will be submitted so you still need to handle that case. When updating the page it is recommend you wait to make sure that the AJAX update of the form data was successful before updating the data in the page. Otherwise, the data may not properly update and the user may not know. I like to provide an informative message when doing a partial update and upon a successful AJAX interaction I will then update the page.