HTML and CSS Reference
In-Depth Information
Listing 13.28 Passing the failure callback
ajax.request(this.url, {
/* ... */
headers: poller.headers,
success: poller.success,
failure: poller.failure
});
The last thing to check is that the complete callback can be used by clients
as well. Testing that it is called when the request completes is no different than
the previous two tests, so I'll leave doing so as an exercise. The implementation,
however, is slightly different, as can be seen in Listing 13.29.
Listing 13.29 Calling the complete callback if available
ajax.request(this.url, {
complete: function () {
setTimeout(function () {
poller.start();
}, interval);
if (typeof poller.complete == "function") {
poller.complete();
}
},
/* ... */
});
13.1.5 The One-Liner
At this point the poller interface is in a usable state. It's very basic, and lacks several
aspects before it would be safe for production use. A glaring omission is the lack
of request timeouts and a stop method, partly because timeouts and abort were
also missing from the ajax.request implementation. Using what you have now
learned you should be able to add these, guided by tests, and I urge you to give
it a shot. Using these methods the poller could be improved to properly handle
problems such as network issues.
As promised in the introduction to this chapter, we will add a simple one-liner
interface to go along with ajax.request , ajax.get and ajax.post . It will
 
Search WWH ::




Custom Search