Thursday, May 14, 2009

Ajax Interview Questions

Ajax Interview questions
  • What is Ajax?
AJAX is not a new programming language, but a new technique for creating better, faster,and more interactive web applications.

Ajax stands for 'Asynchronous JavaScript and XML'

With AJAX, a JavaScript can communicate directly with the server, with the XMLHttpRequest object. With this object, a JavaScript can trade data with a web server, without reloading the page.
  • Ajax is based on which web standards?
- JavaScript
- XML
- HTML
- CSS
  • What is Asynchronous?
The term asynchronous is usually used to describe communications in which data can be transmitted intermittently rather than in a steady stream.
  • How does Ajax works?
With AJAX, JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object.

With the XMLHttpRequest object, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.

The XMLHttpRequest object is supported in all major browsers (Internet Explorer, Firefox, Chrome, Opera, and Safari).
All new browsers use the built-in JavaScript XMLHttpRequest object to create an XMLHttpRequest object (IE5 and IE6 uses an ActiveXObject).
  • What are the important properties of XMLHttpRequest object
- onreadystatechange property

After a request to a server, we need a function to receive the data returned from the server.The onreadystatechange property stores the function that will process the response from a server. The function is stored in the property to be called automatically.

- readyState property

The readyState property holds the status of the server's response. Each time the readyState property changes, the onreadystatechange function will be executed.


- responseText property

The data sent back from a server can be retrieved with the responseText property.

  • How do we send response to the server?
To send a request to the server, we use the open() and send() methods.

The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously.

The send() method sends the request off to the server.