HTML and CSS Reference
In-Depth Information
Listing 12.50 shows the resulting handler.
Listing 12.50 Dispatching success and failure callbacks
function isSuccess(transport) {
var status = transport.status;
return (status >= 200 && status < 300)
status == 304 ||
(tddjs.isLocal() && !status);
function requestComplete(transport, options) {
if (isSuccess(transport)) {
if (typeof options.success == "function") {
} else {
if (typeof options.failure == "function") {
12.6 Making POST Requests
With the GET requests in a fairly usable state we will move on to the subject of
POST requests. Note that there is still a lot missing from the GET implementation,
such as setting request headers and exposing the transport's abort method. Don't
worry, test-driven development is all about incrementally building an API, and given
a list of requirements to meet we can choose freely which ones makes sense to work
on at any given time. Implementing POST requests will bring about an interesting
refactoring, which is the motivation for doing this now.
12.6.1 Making Room for Posts
The current implementation does not lend itself easily to support new HTTP verbs.
We could pass the method as an option, but where? To the ajax.get method?
That wouldn't make much sense. We need to refactor the existing implementation
in three ways: First we need to extract a generic ajax.request method; then
we need to make the HTTP verb configurable. Last, to remove duplication we will
Search WWH ::

Custom Search