HTML and CSS Reference
In-Depth Information
if (options.method == "POST") {
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") { = tddjs.util.urlParams(;
} else { = null;
function request(url, options) {
/* ... */
options = tddjs.extend({}, options);
/* ... */
This somewhat obtrusively blanks data for GET requests, so we will deal with
that immediately. 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