Ajax Interview Questions

Are Finite State Machines (FSM’s) appropriate for use with AJAX?

Possibly There are circumstances under which an FSM might be appropriate. It depends upon the complexity of the environment, and the number of machines that might need to be contacted in order to obtain the response to the request.

Identify and describe the state transitions that can/should occur within a transaction

Reset : When the XmlHttpRequest object is created, no connection yet exists between the clent, and the server.

Open : When the xmlHttp.open() is issued, the request is being prepared for transmission to the server

Sent : When the xmlHttp.send() is issued, the request is transmitted to the server application

Rcvd : When the xmlHttp callback routine is called, the readyState and status fields of the object define why the routine was called

What values exists for the XmlHttpRequest.readyState field, and what do they mean?

readyState values:

0 = uninitialized

1 = loading

2 = loaded

3 = interactive

4 = complete

When is it appropriate to access, or use the other fields within the XmlHttpRequest object?

The most important field is the readyState field. Once a value of 4 (i.e., complete) is received,then the next most important field is status. The value of status will be the same as the HTTP Status Code values

When should AJAX NOT be used?

It would not be appropriate to use AJAX when the “answer/result” can be determinded by the client. Generally, the purpose of AJAX is to submit a short request to the server, and process the response in such a way as to add value to the currently displayed page.It would also not be appropriate to use AJAX when the magnitude of the response is such that it would be easier, and more clear to redisplay the page.

READ  Technologies Used in AJAX

What objects are used by AJAX programs?

The most obvious / correct answer would be “XmlHttpRequest”. However, personally, I would seriously consider someone who discussed the use of the callback routine, and most specifically “the response” as “objects”.

What does AJAX stand for and who coined the phrase?

“Advanced JavaScript And XML”, coined by Jesse James Garret, Adaptive Path – http://adaptivepath.com/publications/essays/archives/000385.php

What Javascript object is used to drive AJAX requests, and how does it differ on various browser?s

XmlHttpRequest. It’s an ActiveX object on IE, but is a native object on the other browsers (Firefox, Mozilla, Opera, Safari, Konqueror)

How do you know that an AJAX request has completed?

The XHR.readyState is 4 and the XHR.status is 200 (or zero if the request is to a local file). The callback function is called four times – first with status=1, then 2,3, and finally 4.

How does XML processing differ on the different browsers?

It’s an ActiveX object on IE, but is native on the other browsers

Is it possible to achieve similar results without the XmlHttpRequest object?

A hidden IFrame (actually an IFrame of size 0px * 0px due to a bug in IE) can be used to retrieve data, and its contents can then be processed in a similar manner to the response from an XHR call.