Set - 4

Question 1 :

How do I create a thread to do AJAX polling?

Answer :

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 2 :

Whats with the -alpha in the install instructions?

Answer :

HTML_AJAX hasn't had a stable release yet and the pear installer doesn't install non stable packages by default unless you specify a version.

Question 3 :

How do I test my AJAX code?

Answer :

There is a port of JUnit for client-side JavaScript called JsUnit

Question 4 :

What exactly is the W3C DOM?

Answer :

The W3C Document Object Model (DOM) is defined by the W3C as the following: The Document Object Model is a platform- and language-neutral interface...

Question 5 :

When will HTML_AJAX have a stable release?

Answer :

Once all the major features are complete and the API has been tested, the roadmap gives an idea of whats left to be done.

Question 6 :

What parts of the HTML_AJAX API are stable?

Answer :

We don't have a list right now, but most of the API is stable as of 0.3.0. There should be no major changes at this point, though there will be lots of new additions.

Question 7 :

What Browsers does HTML_AJAX work with?

Answer :

As of 0.3.0, all the examples that ship with HTML_AJAX have been verified to work with
* Firefox 1.0+
* Internet Explorer 5.5+ (5.0 should work but it hasn't been tested)
Most things work with
* Safari 2+
* Opera 8.5+

Question 8 :

Is the server or the client in control?

Answer :

It depends. With AJAX the answer is more in between. Control can be more centralized in a server-side component or as a mix of client-side and server-side controllers.

* Centralized server-side controller - When having a more centralized controller the key is to make sure the data in client-side page is in sync with that of the server. Some applications may keep all the state on the server and push all updates to client DOM via a simple JavaScript controller.
* Client and server-side controllers - This architecture would use JavaScript to do all presentation related control, event processing, page manipulation, and rendering of model data on the client. The server-side would be responsible for things such as business logic and pushing updated model data to the client. In this case the server would not have intimate knowledge of the presentation short of the initial page that would be sent to the client page request.

There are some use cases where an entire AJAX application can be written in a single page. Keep in mind if you choose this type of architecture that navigation and bookmarking should be considered.
Both methods are viable depending on what you are trying to accomplish. I tend to prefer spreading the control across the client and server.

Question 9 :

Is Ajax just another name for XMLHttpRequest?

Answer :

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.

Question 10 :

How do I abort the current XMLHttpRequest?

Answer :

Just call the abort() method on the request.