Ajax Interview Questions and Answers
Question - 51 : - How do I create a thread to do AJAX polling?
Answer - 51 : - JavaScript does not have threads. JavaScript functions are called when an event happens in a page such as the page is loaded, a mouse click, or a form element gains focus. You can create a timer using the setTimeout which takes a function name and time in milliseconds as arguments. You can then loop by calling the same function as can be seen in the JavaScript example below.
function checkForMessage() {
// start AJAX interaction with processCallback as the callback function
}
// callback for the request
function processCallback() {
// do post processing
setTimeout("checkForMessage()", 10000);
}
Notice that the checkForMessage will continue to loop indefinitely. You may want to vary the increment the interval based on activity in the page or your use cases. You may also choose to have logic that would break out of the loop based on some AJAX response processing condition.
Question - 52 : - How Ajax is Different ?
Answer - 52 : - 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 the server. It seems like adding a layer to the application would make it less responsive, but the opposite is true.
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 user’s behalf. The Ajax engine allows the user’s interaction with the application to happen asynchronously — independent of communication with the server. So the user is never staring at a blank browser window and an hourglass icon, waiting around for the server to do something.
Figure 2: The synchronous interaction pattern of a traditional web application (top) compared with the asynchronous pattern of an Ajax application (bottom).
Every user action that normally would generate an HTTP request takes the form of a JavaScript call to the Ajax engine instead. Any response to a user action that doesn’t require a trip back to the server — such as simple data validation, editing data in memory, and even some navigation — the engine handles on its own. If the engine needs something from the server in order to respond — if it’s submitting data for processing, loading additional interface code, or retrieving new data — the engine makes those requests asynchronously, usually using XML, without stalling a user’s interaction with the application.
Question - 53 : - Is it possible to set session variables from javascript?
Answer - 53 : - 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...
Question - 54 : - What is AJAX Framework?
Answer - 54 : -
ASP.NET AJAX is a free framework to implement Ajax in asp.net web applications. It is used to quickly creating efficient and interactive Web applications that work across all browsers.
Question - 55 : - How can you find out that an AJAX request has been completed?
Answer - 55 : -
ReadyState property is used to check whether AJAX request has been completed. If the property is equal to four, then the request has been completed and data is available.
Question - 56 : - Is javascript knowledge is required to do Ajax?
Answer - 56 : -
Yes, if you plan to develop new AJAX functionality for your web application.
Question - 57 : - What are all the browsers support AJAX?
Answer - 57 : -
Following browsers support AJAX:
- Internet Explorer 5.0 and above
- Opera 7.6 and above
- Netscape 7.1 and above
- Safari 1.2 and above
Question - 58 : - How can you test the Ajax code?
Answer - 58 : -
JSUnit is the client side javascript code used as part of JUnit. JSUnit has been used for Ajax code.
Question - 59 : - Is Ajax said to be a technology platform or is it an architectural style?
Answer - 59 : -
Ajax supports both technology and as architectural style.
Question - 60 : - How can AJAX applications be debugged?
Answer - 60 : -
Two tools are used for debugging:
- Fiddler for IE
- Firebug for Mozilla.