HTML and CSS Reference
In-Depth Information
if (options.method == "POST") {
data = options.data;
}
/* ... */
transport.send(data);
};
This is not optimal, but passes the test without failing the previous one that
expects send to receive null . One way to clean up the ajax.request method
is to refactor to extract the data handling, as Listing 12.62 shows.
Listing 12.62 Extracting a data handling function
function setData(options) {
if (options.method == "POST") {
options.data = tddjs.util.urlParams(options.data);
} else {
options.data = null;
}
}
function request(url, options) {
/* ... */
options = tddjs.extend({}, options);
setData(options);
/* ... */
transport.send(options.data);
};
This somewhat obtrusively blanks data for GET requests, so we will deal with
that immediately.
12.6.2.3 Sending Data with GET Requests
Before we can move on to setting request headers we must make sure that it is
possible to send data with GET requests as well. With GET, data is not passed
to the send method, but rather encoded on the URL. Listing 12.63 shows a test
specifying the behavior.
 
Search WWH ::




Custom Search